homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod rewrite question for canonical issues
mod_rewrite canonical

5+ Year Member

Msg#: 3291047 posted 4:16 pm on Mar 23, 2007 (gmt 0)

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]



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

Msg#: 3291047 posted 10:01 pm on Mar 23, 2007 (gmt 0)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved