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

Bobby
Bobby used Ask the Experts™
on
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]
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
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

Author

Commented:
David,

I dont understand. Are you saying that what i posted will not do what i said we need to do?
Top Expert 2016

Commented:
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?
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

David FavorFractional CTO
Distinguished Expert 2018

Commented:
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

Author

Commented:
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.

Author

Commented:
Ended up doing this, seems to work well:

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

Thanks all for the tips.
Commented:
RewriteRule ^index.html$ / [L,R=301]

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial