Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

301 Re-Direct for Home Page

Going from a index.htm to a index.php

6:19 pm on Dec 9, 2014 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 24, 2002
posts: 512
votes: 5


This is probably too simple, but after reading more articles on the web about this I've become confused and concerned that I might inadvertently screw everything up by improperly doing a 301 permanent re-direct for my home page.

Currently, my home page is a .htm file. Virtually all links lead to the main domain (aka...www.mydomain.com). But some links - both internal and external - link to the full path (aka...www.mydomain.com/index.htm).

So to avoid a bunch of 404's, I need to use a 301 redirect so that anything that leads to www.mydomain.com/index.htm will go to either www.mydomain.com or www.mydomain.com/index.php

For other 301 redirects, I've always just used code in the .htaccess file identical to this:

Redirect permanent /folder-name/file.htm http://www.mydomain.com/folder-name/new-file-name.php

After researching this issue online, I've gotten the feeling that using this simple code might not work when doing it on the home page.

So, I'm asking the experts here. What is the proper way to redirect the home page to go from a index.htm to a index.php.


8:19 pm on Dec 9, 2014 (gmt 0)


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

joined:Aug 10, 2004
votes: 244

first you must ensure that your default directory index document is set to index.php

next you should use mod_rewrite directives instead of mod_alias directives to do all of your external redirects.
the R=301 flag specifies a 301 redirect for the RewriteRule directive.
the Substitution string should specify the full canonical protocol and hostname.

one RewriteRule should specify a Pattern that captures all requested index documents including index.htm and index.php and then redirect those requests to the (trailing slash) root directory of the canonical hostname.
10:40 pm on Dec 9, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
votes: 884

What is the proper way to redirect the home page to go from a index.htm to a index.php.

None, because "index.htm" or "index.php" or for that matter "index.html" or "index.jsp" is not part of the publicly visible URL. (If it currently is, you are about to change it.) What you need, instead, is

#1 a DirectoryIndex line that specifies "index.php" as the first choice (if you're on shared hosting, "index.php" is almost certainly already an option, but probably not the first)
#2 a RewriteRule that redirects all external requests for /directory/index.whatever to /directory/ The same rule, with appropriate capturing, will cover both the root and any subdirectories. This has been discussed approximately eleven thousand times in the present forum, so it should be easy to find.

If you're changing your extension, for example from .htm to .php, give both in the index redirect. You may choose to include other extensions after "index\." but you are also welcome to let these requests get the 404 they deserve. Note that Google (specifically) will request "index.html" for all directories it knows about. So that's one reason to redirect explicitly even if you have never used ".html" as an extension.

Once you've done this, it will never again make any difference what extension your index files use, because human visitors will never see the filename.