【问题标题】:How to prevent second call after rule is applied for mod_rewrite in .htaccess如何在.htaccess中为mod_rewrite应用规则后防止第二次调用
【发布时间】:2010-12-21 16:02:35
【问题描述】:

我有以下 .htaccess 规则:

RewriteEngine on
RewriteRule ^(.*) http://www.server2.com/index.php?action=$1

我需要添加另一个重定向,它应该这样工作:

RewriteRule ^app/(.*) index.php [L]

所以请求不会传递给 server2,而是就地提供。

据我了解,如果我添加这一行,.htaccess 会被第二次调用,我会被重定向到 server2.com/index.php。

我希望,我可以使用某种开关来阻止第二次 mod_rewrite 调用,或者我应该使用 RewriteCond 代替(例如here)?

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    在您的第一条规则中排除第二条规则的模式:

    RewriteCond $1 !^app/(.*)
    RewriteRule ^(.*) http://www.server2.example/index.php?action=$1
    RewriteRule ^app/(.*) index.php [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多