View Full Version : redirect from index.htm to /
UKSBD
4th February 2010, 11:27
I have a problem with a site where the bots are visiting /index.htm even
though the page doesn't exist.
Trying to set a redirect from /index.htm to / just creates a loop (I assume
index.htm is the primary file set up by host)
index.php is the actual page and a redirect from /index.htm to /index.php
works, but I obviously don't want to do that.
How is the best way to redirect from /index.htm to / without creating the loop?
Apache server
C.Pearse
4th February 2010, 12:43
Here is a handy bit of code:
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]Put this in your .htaccess file and any requests for any page ending in .htm will be sent to that page ending in .php.
So...
index.htm = index.php
about_us.htm = about_us.php
Cheers
Chris
awebapart.com
4th February 2010, 13:04
Search bots will try to visit index.htm if it has either been indexed before or it is linked to from elsewhere.
If you want your default root home page to make use of your index.php page, and your index.htm permanently redirected to your root home page (which in turn makes use of index.php), then there are a number of ways of doing this, and one way is putting the following in your .htaccess file:
DirectoryIndex index.php
Redirect permanent /index.htm http :// www .domain .com
(without the spaces between http and the .com, and use your own domain name)
Once that is redirecting, it is also worth checking that you are not internally linking to index.htm within the website (the double home page (http://www.ukbusinessforums.co.uk/forums/showthread.php?t=109029&page=2) issue).
UKSBD
4th February 2010, 14:42
Redirect permanent /index.htm http :// www .domain .com
(without the spaces between http and the .com, and use your own domain name)
I did that earlier, but because index.htm appears to be set as the default
file extension it was effectively creating a loop.
I've contacted the host about changing the order of file extensions so
as to make index.php overrule the others, but not heard back yet.
Is there another way to do it if the host won't make the changes?
KM-Tiger
4th February 2010, 14:47
Yes, as Paul said put:
DirectoryIndex index.php
in .htaccess.
But that will be dependent on your host's config allowing that override. You would need to check with them.
UKSBD
4th February 2010, 15:15
would that not just send /index.htm to /index.php rather than / ?
awebapart.com
4th February 2010, 15:28
would that not just send /index.htm to /index.php rather than / ?
No.
DirectoryIndex index.php
does not perform a redirect from / to another url. The web address (url) remains / but the server executes the file index.php
Also, whenever you are testing these kind of chenges, you might need to clear your browser cache to see the change take affect.
UKSBD
4th February 2010, 15:35
DirectoryIndex index.php
Redirect permanent /index.htm http :// www .domain .com
(without the spaces between http and the .com, and use your own domain name)
Thanks, I missed the first line earlier.
by adding DirectoryIndex index.php
obviously gave index.php preference over index.htm and the redirect back
to / has now broken the loop.
UKSBD
4th February 2010, 15:40
Another question
does
DirectoryIndex index.php
only effect the directory the .htaccess is in?
There may be other directories where index.htm might want to take
preference over index.php
awebapart.com
4th February 2010, 15:43
It usually applies further down the child sub-folders too. If you want to override these settings for a particular sub-folder, place a .htaccess file in the relevant sub-folder.
KM-Tiger
4th February 2010, 16:05
Or you could:
DirectoryIndex index.php index.html
index.php will be served if present, if not then index.html will be served.
But be careful. If neither is present then Apache will give a directory listing unless Options Indexes is turned off, which it may be in your hosts settings. If not then
Options -Indexes
in your .htaccess will do it (again providing your host allows the override).
If you've got a *lot* of sub-directories that might be less work to set up and maintain.