2012-09-16 57 views
1

将codeigniter网站重定向到www域的最佳方式是什么?我想到的唯一方法是使用htaccess进行此操作,但无法确切知道如何操作。这是我现在用来从url中删除index.php的重写规则。我应该如何正确添加重定向到www域?将域重定向到codeigniter上的www

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|assets|uploads|robots\.txt|favicon\.png|favicon\.ico) 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

更新您的DNS记录 – nullpotent

回答

5

看到这个URL

.htaccess Redirect non-WWW to WWW preserving URI string

或者尝试

RewriteCond %{HTTP_HOST} . 

RewriteCond %{HTTP_HOST} !^www.mysite.com [NC] 

RewriteRule (.*) http://www.mysite.com/$1 [R=301,L] 

又如

看到这个URL

Codeigniter redirects for a new domain

试试吧

尝试增加你的的根目录下面的的.htaccess文件 www.xyz.com网站。

RewriteEngine on 
RewriteBase/

#redirect www.xyz.com/A/B/controller/function 
#www.xyz.com/B/controller/function 
RewriteCond %{HTTP_HOST} ^www\.xyz\.com$ [NC] 
RewriteRule ^A/(B/[\w]+/[\w]+)$ /$1 [L,NC,R=301] 


#redirect www.xyz.com/A/controller/function to 
#www.abc.com/controller/function 
RewriteCond %{HTTP_HOST} ^www\.xyz\.com$ [NC] 
RewriteRule ^A/([\w]+/[\w]+)$ http://www.abc.com/$1 [L,NC,R=301] 
+0

我已经使用了前三行代码,但我的页面仍然重定向,如 (mysite.com/about-us)到(www.mysite.com/index.php?/about -我们) –

2

添加另一个条件是:

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
2

在您的DNS中使用CNAME record

这节省了HTTP请求,所以是最有效的选择。