Forum Moderators: phranque

Message Too Old, No Replies

Redirecting index.htm

         

JWJonline

7:42 pm on Apr 11, 2006 (gmt 0)

10+ Year Member



My homepage is index.php and I'm getting 404's from people landing on index.htm. I am trying to use Redirect Permanent to redirect index.htm to index.php but this causes hits on my subdomains to be redirected to my main site also.

What can I do to prevent this?

Thanks

jdMorgan

8:40 pm on Apr 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I'm getting 404's from people landing on index.htm

Why? Do you have links to that URL? Are you sure these are legitimate requests?

The problem's easy enough to fix. Instead of using mod_alias Redirect or RedirectMatch directives, use mod_rewrite instead. Before redirecting, though, check the requested hostname to be sure it's not one of the not-to-be-redirected subdirectories.


DirectoryIndex index.php
#
Options +FollowSymLinks
RewriteEngine on
#
# If main domain or www subdirectory only
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
# redirect requests for "index.htm" to "/"
RewriteRule ^index\.htm$ http://www.example.com/ [R=301,L]

Note that the code declares index.php as the index file, and then redirects requests for www.example.com/index.htm or example.com/index.htm to www.example.com/

That's the recommended way to do this -- Link to example.com/ as your home page. Don't used index.anything as your home page URL in links or anywhere else. There is no reason to publish your Web site's technology (.html, .php), and this makes your URL shorter and easier to remember, and makes your site look more professional.

Jim

JWJonline

9:25 pm on Apr 11, 2006 (gmt 0)

10+ Year Member



>Why? Do you have links to that URL? Are you sure these are legitimate requests?

Yes, to both questions. I have only recently converted to php and I have a lot of html (and shtml) links spread around the 'net.

Thanks for the solution Jim ... I wouldn't have come up with that in a million years. The only thing I've thought of (since posting) is to set up an Apache Handler to parse htm as php and then have a dummy index.htm with the single line <?php header("location: index.php");?>. Seems a bit of a botch and I'm much happier with your method.

Thanks