我正在尝试重写以下模式的所有网址:
http://example.com/csfdg/anything
进入http://example.com/csfdg/index.html
我的根级别的 .htaccess 文件包含以下内容:
Options +FollowSymLinks
RewriteEngine On
RewriteRule \/csfdg\/.* /csfdg/index.html [L]
检查器位于 http://htaccess.madewithlove.be/告诉我它会按照我想要的方式重写我的网址,但是当我转到 http://example.com/csfdg/anything
时我刚刚得到 404。很难判断发生了什么,但我知道 RewriteEngine 正在工作,因为如果我对其进行足够多的干扰,我可能会发生 500 个错误:)
有什么想法吗?谢谢
最佳答案
你可以使用这个:
RewriteEngine on
RewriteCond %{REQUEST_URI} !index\.html$
RewriteRule ^([^/]+)/.+$ /$1/index.html [L]
RewriteConditon 在这里很重要,可以避免将 /foo/index.html 重写为自身。
关于regex - mod_rewrite 全部/某些内容到index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37802809/