Hey guys, I'm trying to use a rewrite rule to force no www. on my site's URLs. I've used the following, but it's conflicting with my previous rewrite rules. # -Manipulate URLs- RewriteEngine on RewriteRule ^index/?$ index.php [L] RewriteRule ^hosting/?$ hosting.php [L] RewriteRule ^support/?$ support.php [L] RewriteRule ^about_us/?$ aboutus.php [L] RewriteRule ^testimonials/?$ testimonials.php [L] RewriteRule ^terms/?$ terms.php [L] RewriteRule ^privacy/?$ privacy.php [L] RewriteRule ^site_map/?$ sitemap.php [L] # -Force non-www URLs- RewriteCond %{HTTP_HOST} ^www\.websolvents\.com$ [NC] RewriteRule ^(.*)$ http://websolvents.com/$1 [R=301,L] Code (markup): If I enter http://www.websolvents.com/hosting/ , it will rewrite to http://websolvents.com/hosting.php , which is incorrect. I want it to rewrite to http://websolvents.com/hosting/ . Any ideas? Thanks much! Kyle
If you want to redirect to non-www only and no other redirect then you can mark out all these line #RewriteRule ^index/?$ index.php [L] #RewriteRule ^hosting/?$ hosting.php [L] #RewriteRule ^support/?$ support.php [L] #RewriteRule ^about_us/?$ aboutus.php [L] #RewriteRule ^testimonials/?$ testimonials.php [L] #RewriteRule ^terms/?$ terms.php [L] #RewriteRule ^privacy/?$ privacy.php [L] #RewriteRule ^site_map/?$ sitemap.php [L] Code (markup):
It's doing what you're telling it to. Firstly www.websolvents.com/hosting/ will get rewritten to www.websolvents.com/hosting.php You then have your non-www lines that will redirect the requested page: www.websolvents.com/hosting.php to websolvents.com/hosting.php Put the non-www lines above the others and it should be fine.
# -Manipulate URLs- Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^index/$ index.php [L] RewriteRule ^hosting/$ hosting.php [L] RewriteRule ^support/$ support.php [L] RewriteRule ^about_us/$ aboutus.php [L] RewriteRule ^testimonials/$ testimonials.php [L] RewriteRule ^terms/$ terms.php [L] RewriteRule ^privacy/$ privacy.php [L] RewriteRule ^site_map/$ sitemap.php [L] # -Force non-www URLs- RewriteCond %{HTTP_HOST} ^www\.websolvents\.com$ [NC] RewriteRule ^(.*)$ http://websolvents.com/$1 [R=301,L] and you can try it with the -Force non-www URLs- part first.