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

无人久伴 提交于 2020-01-02 07:01:07

问题


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?


回答1:


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

You only need:

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



回答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/



来源:https://stackoverflow.com/questions/27188604/htaccess-redirect-index-html-to-index-php-for-domain-root-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!