【问题标题】:Mod Rewrite stop at rule?Mod Rewrite 停止规则?
【发布时间】:2021-02-26 05:37:24
【问题描述】:

我的 .htaccess 中有以下 mod 重写,当我转到 /commPortal.php 时,它仍然最终将我路由到 index2.php。

RewriteRule ^commportal/(.+)$ commPortal.php?data=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index2.php [QSA,L]

RewriteCond %{REQUEST_URI} \.php [NC]
RewriteRule ^ index2.php [QSA,L]

这似乎是由于 RewriteRule ^commportal/(.+)$ commPortal.php?data=$1 [L] 然后被以下人员接听了:

RewriteCond %{REQUEST_URI} \.php [NC]
RewriteRule ^ index2.php [QSA,L]

有没有办法让RewriteCond %{REQUEST_URI} \.php [NC] 看到 commPortal.php 而不是 /commportal,或者如果已经有匹配的重写规则,甚至可以忽略它?

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting friendly-url


    【解决方案1】:

    将您的最后一条规则更改为:

    RewriteRule ^commportal/(.+)$ commPortal.php?data=$1 [L,QSA,NC]
    
    RewriteRule ^index2\.php$ - [L,NC]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index2.php [L]
    
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule \.php$ index2.php [L,NC]
    

    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 条件只有在此规则之前没有内部重写时才会为真,因此仅在执行此规则之前没有触发其他规则。

    另一种使用THE_REQUEST 变量的选项,其中包含原始 请求而不是重写的请求:

    RewriteCond %{THE_REQUEST} !\s/+commportal/ [NC]
    RewriteRule \.php$ index2.php [L,NC]
    

    【讨论】:

      【解决方案2】:

      您能否尝试以下操作,仅基于您显示的示例。请确保在测试您的 URL 之前清除您的浏览器缓存。

      RewriteRule ^commportal/(.+)$ commPortal.php?data=$1 [NC,L]
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index2.php [QSA,L]
      
      RewriteCond %{REQUEST_URI} !commportal\.php/?$ [NC]
      RewriteCond %{REQUEST_URI} \.php [NC]
      RewriteRule ^ index2.php [QSA,L]
      

      【讨论】:

        猜你喜欢
        • 2011-07-20
        • 2015-09-22
        • 1970-01-01
        • 1970-01-01
        • 2016-07-17
        • 1970-01-01
        • 1970-01-01
        • 2013-01-13
        • 1970-01-01
        相关资源
        最近更新 更多