Link to home
Start Free TrialLog in
Avatar of Bobby
BobbyFlag for United States of America

asked on

301 redirect mod_rewrite to strip /index.html, will this snippet work?

I want any request that goes to mysite.com/index.html to be 301 redirected to mysite.com

Will the following mod_rewrite work in my htaccess file, is it comprehensive enough, and where would it need to be placed in the file?

RewriteCond %mysite.com/index.html HTTP [NC]
RewriteRule (.*)index.html$ /$1 [R=301,L]
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

mysite.com will load the default document which is probably index.html
if you want to change it in your httpd.conf i.e.
DirectoryIndex home.php
Avatar of Bobby

ASKER

David,

I dont understand. Are you saying that what i posted will not do what i said we need to do?
if index.html is your default page then
http://mysite.com and http://mysite.com/index.html is exactly the same as the web server when given http://mysite.com will load the default document if it exists.

What page do you want the web server to load?
Likely what you're looking for is something like this...

RewriteCond %{THE_REQUEST} ^.*/index.html 
RewriteRule ^(.*)index.php$ http://www.domain.com/$1 [R=301,L] 

Open in new window

Avatar of Bobby

ASKER

This is for SEO reasons... I know the server will already do that but we want results displayed without the /index.html and this may help with that.

David F, that looks exactly like where I got this:

RewriteCond %mysite.com/index.html HTTP [NC]
RewriteRule (.*)index.html$ /$1 [R=301,L]

You think that will do it? Do you know where in the htaccess file it needs to go? Im not even sure how you test something like this.
Avatar of Bobby

ASKER

Ended up doing this, seems to work well:

RewriteRule ^index.html$ / [L,R=301]

Thanks all for the tips.
ASKER CERTIFIED SOLUTION
Avatar of Bobby
Bobby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial