Forum Moderators: phranque
# Redirect non-www to www URL
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]# Redirect index.php to example.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
Google has got the redirects right, but Yahoo! seems to have dropped ALL my www URLs and only kept non-www URLs. Is my htaccess code okay or is there a way to make it more efficient (somehow combine the 2 instructions above)?
[edited by: jdMorgan at 2:54 pm (utc) on Jan. 30, 2008]
[edit reason] example.com [/edit]
RewriteEngine on
#
# Redirect client requests for /index.php to www.example.com/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
# Redirect requests for all resources in non-www domain to canonical www domain
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
However, I doubt that any of this has anything to do with your Yahoo! problem -- I've seen far worse mistakes with less impact. If your site has been on-line for awhile, be sure to pick the domain variant (www or non-www) that has the most/best incoming links as your canonical domain, unless 'branding issues' are more important to you (Selection of the canonical domain is another subject entirely, and has been much discussed here already).
As noted in many threads here, the now-first rule can optionally be rewritten to handle /index.php requests in any subdirectory if your site has such a problem:
# Redirect client requests for /<any-directory>/index.php to www.example.com/<any-directory>/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]