简体   繁体   English

如何使用mod-rewrite(iirf)仅重定向php文件

[英]how do i redirect only php files with mod-rewrite (iirf)

I currently have redirects (using IIRF, but i believe this to be the same as .htaccess rules) set up so that all files don't get redirected, and just go straight to the filepath in the URL, but everything else gets redirected to /index.php Using the code below: 我目前有重定向(使用IIRF,但我相信这与.htaccess规则相同)设置,以便所有文件都不会被重定向,只是直接进入URL中的文件路径,但其他一切都被重定向到/index.php使用以下代码:

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]

I need it to also redirect any .php file (but only .php files) to index.php (same as the second rule) 我需要它还将任何.php文件(但只有.php文件)重定向到index.php(与第二条规则相同)

In summary, 'www.example.com/foo' AND 'www.example.com/foo.php' both need to go to the index page, but 'www.example.com/foo.js' and 'www.example.com/foo.css' (etc!) do not. 总之,“www.example.com/foo”和“www.example.com/foo.php”都需要转到索引页面,但是“www.example.com/foo.js”和“www.example” .com / foo.css'(等等!)没有。

Try: 尝试:

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]

我想,你需要这样的东西

RewriteCond %{REQUEST_FILENAME} *.php$

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

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