Twitter LinkedIn Google+
WP Greet Box icon

Welcome back, visitor!. You might want to subscribe to the RSS feed for online marketing info as Todd posts it.

Switch Reading StyleNighttimeDaytime

Redirecting www to non-www

Online marketing information can change quickly This article is 8 years and 364 days old, and the facts and opinions contained in it may be out of date.

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.

More information about Todd Malicoat aka stuntdubl.

Twitter LinkedIn Google+ 

  • http://www.wolf-howl.com graywolf

    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.

  • http://www.smart-it-consulting.com/catindex.htm?node=2 Sebastian

    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.

  • Pingback: Installing Wordpress and Setting Permalinks

Buffer