我目前设置了重定向(使用 IIRF,但我相信这与 .htaccess 规则相同)以便所有文件都不会被重定向,而是直接转到 URL 中的文件路径,但其他所有内容被重定向到/index.php 使用以下代码:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]
我还需要它来将任何 .php 文件(但仅限 .php 文件)重定向到 index.php(与第二条规则相同)
综上所述,'www.example.com/foo' 和 'www.example.com/foo.php' 都需要转到索引页,但是 'www.example.com/foo.js' 和 ' www.example.com/foo.css'(等等!)没有。
最佳答案
尝试:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !index\.php
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]
关于php - 我如何使用 mod-rewrite (iirf) 只重定向 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16061355/