【问题标题】:in mod_rewrite how can I write a rule that redirect everything except everything for a specific directory?在 mod_rewrite 中,我如何编写一个规则来重定向除特定目录的所有内容之外的所有内容?
【发布时间】:2011-02-08 17:27:33
【问题描述】:

在我的 Apache 服务器上,我有以下规则:

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule (.*) /shindig/index.php [L]
</IfModule>

这会将每个请求重定向到 /shindig/index.php, 我想重定向除此路径中的任何请求之外的每个请求:/myOrigPath

我该怎么做?请假设我对 mod_rewrite 几乎一无所知

谢谢

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    您可以使用另一个 RewriteCond 并排除该路径:

    RewriteCond %{REQUEST_URI} !^/myOrigPath
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) /shindig/index.php [L]
    

    您还可以使用$0(全匹配)或$1(第一组匹配)检查RewriteRule 模式的匹配值,而不是%{REQUEST_URI}

    【讨论】:

      猜你喜欢
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      相关资源
      最近更新 更多