Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to always remove WWW from a url with mod_rewrite?

Tags:

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?

like image 615
Yeti Avatar asked Mar 02 '10 07:03

Yeti


1 Answers

Here’s a more generalized solution:

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
like image 84
Gumbo Avatar answered Sep 23 '22 15:09

Gumbo