Forum Moderators: phranque

Message Too Old, No Replies

trouble redirecting extensions

         

sodani

4:51 pm on Jun 29, 2007 (gmt 0)

10+ Year Member



I recently changed all the extensions on my site from .shtml to .php. I'm using the following redirect in my .htaccess file:
RedirectMatch 301 (.*)\.shtml$ [domain.com$1.php...]

This does the trick for every page except that now I'm having a problem with the homepage - www.domain.com is getting redirected to www.domain.com/index.php. I don't want www.domain.com to get redirected. Does anyone know what might be the problem here and how to get around it?

I would think that apache would just serve up whatever index.(ext) file is available when www.domain.com is requested, so I'm confused why it's redirecting to www.domain.com/index.php.

Any ideas?

jdMorgan

6:05 pm on Jun 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check for a DirectoryIndex directive in .htaccess or in your server config file. Make sure that it is updated to specify that index.php is the directory file to use when "/" is requested. This will prevent your .shtml-to-php redirect from being invoked and exposing the filename.

The next time you go through this exercise, consider dropping the file extensions completely from your URLs, so you'll never have to change your URLs and lose your search ranking again. It is a fairly simple matter to internally rewrite requests for extensionless URLs to files with filetypes.

As a matter of fact, you shouldn't have changed your URLs at all: You could simply have told the server to process .shtml files as PHP files, and left your URLs alone... :(

Jim