6

I have a htaccess rule which redirects the index.html to index.php

  RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
  RewriteRule ^(.*)index\.html$ /$1index.php [R=301,L]

This works fine - when I call http://mydomainname.com/index.html , it redirects me to http://mydomainname.com/index.php

but I got one problem, when there is a file in subfolder named index.html then my htaccess rule takes that to index.php.

Example - http://mydomainname.com/subfolder/index.html to http://mydomainname.com/subfolder/index.php and this should not happen for subfolders.

Any solution?

2 Answers 2

12

That rule is probably a bit over-complicated for what you're doing.

You only need:

RewriteRule ^index.html$ /index.php [R,L]
Sign up to request clarification or add additional context in comments.

1 Comment

[R]:Redirect, [L]:Last - doesn't process any more rules though I have a feeling [R] on its own implies [L] anyway
2

Try this. It work's in my case.

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html?$ / [NC,R,L]

Visit: https://css-tricks.com/how-to-redirect-indexhtml-to-indexphp/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.