【发布时间】:2022-11-02 22:38:21
【问题描述】:
有没有办法让 httpd RewriteRule 重定向到 index.php,如果存在则 index.html?
喜欢:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule (.*) - [S=2]
RewriteRule (.*) /index.(php|html)?q=$1 [L]
优先使用 php(如果存在),然后回退到 html。
if index.php:
foo.bar/test -> foo.bar/index.php?q=test
else
foo.bar/test -> foo.bar/index.html?q=test
【问题讨论】:
-
我想你会通过额外的
RewriteCond和index.php和-f来做到这一点 -
可以使用位于 httpd.conf 文件中的
DirectoryIndex index.php index.html index.htm来完成。事实上,它可能已经存在 -
@RiggsFolly,这些天我很少使用Apache,这适用于这样的路由器脚本吗?
-
但是当 RewriteRule 有特定的文件要处理时,不会出现错误。这可能只需要 / 而不是 /index.html 吗?
标签: php mod-rewrite