【问题标题】:how do i redirect only php files with mod-rewrite (iirf)我如何使用 mod-rewrite (iirf) 仅重定向 php 文件
【发布时间】:2013-04-17 13:27:44
【问题描述】:

我目前设置了重定向(使用 IIRF,但我相信这与 .htaccess 规则相同),这样所有文件都不会被重定向,而是直接转到 URL 中的文件路径,但其他所有文件被重定向到 /index.php 使用下面的代码:

RewriteCond %{REQUEST_FILENAME} !-f

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

我还需要它来将任何 .php 文件(但只有 .php 文件)重定向到 index.php(与第二条规则相同)

综上,'www.example.com/foo' AND 'www.example.com/foo.php' 都需要去索引页,但是 'www.example.com/foo.js' 和 ' www.example.com/foo.css'(等等!)没有。

【问题讨论】:

    标签: php .htaccess mod-rewrite rewrite iirf


    【解决方案1】:

    试试:

    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]
    

    【讨论】:

      【解决方案2】:

      我想,你需要这样的东西

      RewriteCond %{REQUEST_FILENAME} *.php$
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-05
        • 1970-01-01
        • 2011-05-06
        • 1970-01-01
        • 2013-12-26
        • 2012-04-18
        • 1970-01-01
        • 2017-02-25
        相关资源
        最近更新 更多