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 15 years and 243 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 ^.*${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, 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 

  • 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.

  • Sebastian

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

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

  • Pingback: Installing Wordpress and Setting Permalinks