开发者

Redirect non WWW urls to WWW urls through htaccess

I am using apache 2.2 on a windows OS , I need to redirect non www urls to www urls , i checked online , and found this seems to be working for many

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

But if i use the same re开发者_如何学Pythonwrite rules i get www urls with a dot in the end :

ex :

http://example.com/test redirects to
http://www.example.com.
$1 is "." and its failing to add all params


Ok!
you put this on you .htaccess file:

RewriteCond %{HTTP_HOST} ^mysite\.local [NC] 
RewriteRule ^(.*)$ mysite.local/$1 [R=301,L] 

it means if host equals to mysite.local (end of host not mentioned!) so every url redirects to directory mysite.local!
You should use this:

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

So every URL that host IS NOT equal to www.mysite.local will redirect to this one! but remember if you want to create subdomain, PUT DOCUMENT ROOT OF THIS SUBDOMAIN OUT OF WWW.MYSITE.LOCAL DOCUMENT ROOT! (it's better!)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜