I'm using the following to try and remove WWW from the url:
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://example.com$1 [R=301]
But for some reason it doesn't work. Any suggestions?
I'm using the following to try and remove WWW from the url:
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://example.com$1 [R=301]
But for some reason it doesn't work. Any suggestions?
Try:
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
And without mod_rewrite
:
<VirtualHost 10.0.0.1:80>
ServerName www.example.com
Redirect permanent / http://example.com/
</VirtualHost>
Virtual hosts can be used by completing the steps in the following URL: Setting Up A Virtual Host in Apache.
Here’s a more generalized solution:
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]