简体   繁体   English

htaccess仅将index.html重定向到index.php

[英]htaccess redirect index.html to index.php for domain root only

I have a htaccess rule which redirects the index.html to index.php 我有一个htaccess规则,它将index.html重定向到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 这很好 - 当我调用http://mydomainname.com/index.html时 ,它会将我重定向到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. 但是我遇到了一个问题,当子文件夹中有一个名为index.html的文件时,我的htaccess规则将其带到index.php。

Example - http://mydomainname.com/subfolder/index.html to http://mydomainname.com/subfolder/index.php and this should not happen for subfolders. 示例 - http://mydomainname.com/subfolder/index.htmlhttp://mydomainname.com/subfolder/index.php ,这不应该发生在子文件夹中。

Any solution? 有解决方案吗

That rule is probably a bit over-complicated for what you're doing. 对于你正在做的事情,这个规则可能有点过于复杂。

You only need: 你只需要:

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

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//css-tricks.com/how-to-redirect-indexhtml-to-indexphp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM