Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirect index.html to index.php for domain root only

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?

like image 923
D3Systems Avatar asked Nov 28 '14 12:11

D3Systems


People also ask

How do I redirect a domain to index HTML?

Add the following lines of code to the file: Redirect /index. html http://www.example.com/ Replace example.com with your domain name. Save the file and upload it to your web server.

How do I redirect a PHP file to an html file?

php file in the directory you wish to redirect from with the following content: < ? php header("Location: http://www.redirect.to.url.com/"); ?> Where 'http://www.redirect.to.url.com/' is the URL you wish the users to be redirected too.


1 Answers

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

You only need:

RewriteRule ^index.html$ /index.php [R,L]
like image 61
arco444 Avatar answered Nov 14 '22 22:11

arco444