Stuntdubl Business Search Marketing Consulting

Redirecting www to non-www

If you're new here, you may want to learn more about me, introduce yourself or check out my best posts. Thanks for visiting!

I had several examples of 301 redirecting the other way around, from non-www to www, but hadn’t ever had to redirect from www to non-www for anything.

In case your wondering, and don’t ever want the headache I have from my eyes crossing from mod-rewrite, here is how to do it:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule ^.*$ http://example.com%{REQUEST_URI} [R=301,L]

If you have more rewrite questions, you can try the mod rewrite cheat sheet, or the URL re-writing tools, or the guide to 301 redirects.

Don’t redirect to example.com, and be sure to check your header responses when you are through.

Thanks to Louis, and a gent who does teak furniture for their assistance in this fiasco.

I love Social Media! - Votes are noticed and appreciated:
  • del.icio.us
  • digg
  • Fark
  • Reddit
  • YahooMyWeb

2 Comments Leave a comment »

The URI to TrackBack this entry is: http://www.stuntdubl.com/2005/10/24/non-www-redirect/trackback/

graywolf
October 24th, 2005,
6:31 pm

I do it without the “www” for “branding” or heck just because it sound “nicer”. The REQUEST URI is a new one for me, going to have to try that out.

Sebastian
October 25th, 2005,
4:57 am

RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule (.*) http://example.com/1 [R=301,L]

should do the trick too, and it covers case issues in the server name.

Leave a Reply