Forum Moderators: phranque

Message Too Old, No Replies

Is my .htaccess content correct?

         

andrewshim

10:08 am on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd like to redirect all non-www to www and index.php to root with my .htaccess.

However, I think my code is causing google problems to crawl my site. This is the content of my .htaccess file?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

# Redirect index.php to domain.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]

The second section is a cut and paste job from one of the threads here, but since including it, I have been getting errors in my sitemaps reporting.

Any help is appreciated!

jdMorgan

2:01 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks OK to me.

The only way this might cause a problem with GWT Sitemaps is if some of your pages link to "/index.php" instead of to "/". Once you've installed this code, you should never link on your own site to "/index.php". You should consistently link only to "/".

Also, the code will not rewrite "/index.php" to "/" if the request for index.php has a query string appended to it. It will also rewrite only the /index.php file only in your top-level directory, and no others. You'll have to decide if that is what you want or not.

Jim

andrewshim

3:33 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks jim...

if the .htaccess is okay, then I need to look at what else is causing my sitemap problem.

g1smd

9:23 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is one problem with that code.

A request for domain.com/index.php will be redirected to www.domain.com/index.php and then that will again be redirected to www.domain.com. You need to avoid just such a redirection chain.

The solution is simple. Put the more specific redirect rule first, with that rule not just forcing the index page to "/", but make it also force the www at the same too.

The second rule will then force all remaining domain.com URLs to the www version. This rule will not run for index pages. The first rule will have already taken care of them.