Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite question for canonical issues

mod_rewrite canonical

4:16 pm on Mar 23, 2007 (gmt 0)

5+ Year Member

OK, so I need to generate the code to create a 301 redirect from a www version of a website to a non-www version. I found this code which works well for the opposite case (non-www to www). Can alyone help me rewrite this to make the opposite condition true?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}!^www\.domain\.com$
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html\ HTTP/
RewriteRule index\.html$ [domain.com...] [R=301,L]

10:01 pm on Mar 23, 2007 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

please refer to jdMorgan's response in this thread for the htaccess url canonicalization library [webmasterworld.com].
after making some minor tweaks to your code, try it and report on your results.