【问题标题】:Do not redirect if some RewriteCond is matched如果某些 RewriteCond 匹配,则不要重定向
【发布时间】:2012-08-05 09:47:22
【问题描述】:

我在 httpd.conf 文件中写了一些规则。它工作正常。我想写一个 RewriteCond 使它应该匹配第一个和第二个参数并且如果它匹配不应该重定向。

如果 URL 是 mobile/login 或 mobile/admin 重定向不应该发生,我该怎么做。

-- 更新--

RewriteCond %{HTTP_USER_AGENT} "!(android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile|Nokia*| Opera*)" [NC]
 RewriteCond $1 !web
 RewriteCond $2 !login
 RewriteCond $2 !admin
 RewriteRule ^(.*)$ /web/index.php [R,L]

这里 2 美元的部分对我不起作用。

【问题讨论】:

  • 如果您包含 httpd.conf 文件的相关部分,这可能会有所帮助。

标签: apache


【解决方案1】:

在 RewriteRule 的模式开头添加 ! 字符。

更多信息请参见the documentation

更新

$2 对您不起作用,因为您的 RewriteRule 模式只有一组捕获括号。这可能是您正在寻找的:

RewriteCond %{HTTP_USER_AGENT} "!(android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile|Nokia*| Opera*)" [NC]
RewriteCond $1 !(web|mobile/login|mobile/admin)
RewriteRule ^(.*)$ /web/index.php [R,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 2011-10-28
    • 2014-04-16
    相关资源
    最近更新 更多