htaccess仅将域名根目录将index.html重定向到index.php [英] htaccess redirect index.html to index.php for domain root only
问题描述
我有一个htaccess规则,可将index.html重定向到index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1index.php [R=301,L]
这很好用-当我调用 http://mydomainname.com/index.html 时,它将我重定向到 http://mydomainname.com/index.php
但是我遇到一个问题,当子文件夹中有一个名为index.html的文件时,我的htaccess规则会将其带到index.php.
示例- http://mydomainname.com/subfolder/index.html 到 http://mydomainname.com/subfolder/index.php ,子文件夹不应发生这种情况.>
有解决方案吗?
对于您正在做的事情,该规则可能有些复杂.
您只需要:
RewriteRule ^index.html$ /index.php [R,L]
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?
That rule is probably a bit over-complicated for what you're doing.
You only need:
RewriteRule ^index.html$ /index.php [R,L]
这篇关于htaccess仅将域名根目录将index.html重定向到index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!