I have a website structured:
- root
- .htaccess
- wordpress installation
- folder xxx
- wordpress
In my .htaccess I have this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
The problem is that it don't allow me to go in:
www.mywebsite.it/xxx
because a loop redirection happen. If I erase the rule, all goes good. How can I modify it? I want that if user type mywebsite.it/ or mywebsite.it/xxx, it is redirected to www version.
my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thanks a lot.
This rule works in isolation but Wordpress stuff is hijacking over it. Slightly modified rule:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
line in DOCUMENT_ROOT/.htaccess
WP permalink structure
you have site address with www.
otherwise WP will again send it back to non-www If you have any .htaccess
below root then they should this additional line below RewriteEngine On
line:
RewriteOptions Inherit
Also test in a different browser to avoid 301 caching.
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.