I am using mod_rewrite for clean URL’s. Until now, everything is working fine :
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) application.php?request=$1 [L,QSA]
</IfModule>
But then, I just try to add another rule that transforms the www.mysite.com urls mysite.com , using the following :
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Results : when I access mysite.com it’s fine, but when accessing www.mysite.com , the URL becomes an ugly mysite.com/application.php?request=
How can I adjust my .htaccess file so there is no conflicts ?
You need to make sure the redirect rule is before the routing rule, otherwise the routing rule gets applied, the rewrite engine loops (will continue to loop until the URI stops changing) and then the redirect happens, on the rewritten URI.