I would like redirect site on start if address is without www. For example if:
http://page.com - should redirect to http://www.page.com
http://page.com/news/first - should redirect http://www.page.com/news/first
i have:
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
why this not working? How can i make it?
Try this code:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Give this a try. Place these as the first lines in your .htaccess
. If you already have the RewriteEngine on
statement just ignore it and use the last two lines.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.).+$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.