【问题标题】:Rewrite condition not kicking in - Apache mod-rewrite based on existence of a query string -重写条件未启动 - Apache mod-rewrite 基于查询字符串的存在 -
【发布时间】:2014-06-25 17:54:29
【问题描述】:

我有一个要求,如果一个链接有一个特定的查询字符串参数,那么它应该被拦截并重定向到另一个 url 我当前的配置是这样的

<IfModule rewrite_module>
RewriteEngine On
RewriteLog /cfp/apps/t/ts/x/logs/mod_rewrite.log
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} /link_source/
RewriteRule (link_source=email) http://dev1.domain.net:12080/m [R]
</IfModule>

我的测试网址是这个

http://dev1.domain.net/web/messages/7029?link_source=email

我希望这个 url 被这个规则捕获(因为 link_source 作为查询字符串存在)并重定向到新的 url,但是这似乎没有发生

在重写日志中,这是我看到的

102.2.81.95 - - [25/Jun/2014:13:41:18 --0400] [devash-ecfpwb01.svr.us.jpmchase.net/sid#d625588][rid#d7aec60/initial] (2) init rewrit
e engine with requested uri /a/messages/7029
102.2.81.95 - - [25/Jun/2014:13:41:18 --0400] [devash-ecfpwb01.svr.us.jpmchase.net/sid#d625588][rid#d7aec60/initial] (3) applying pa
ttern '(link_source=email)' to uri '/a/messages/7029'
102.2.81.95 - - [25/Jun/2014:13:41:18 --0400] [devash-ecfpwb01.svr.us.jpmchase.net/sid#d625588][rid#d7aec60/initial] (1) pass through /a/messages/7029

为什么这条规则没有生效,而且它还从日志中打印 url 减去请求参数。有没有办法启用对请求的查询参数的日志记录。

请帮忙

【问题讨论】:

  • / 在 mod_rewrite 中没有任何意义。假设您使用的是正则表达式模式,因此 / 不是模式分隔符,它只是一个斜杠。所以你说寻找看起来像 / 后跟 l 后跟 i 等的文本...
  • 感谢 Marc 您的回答也有帮助。感谢您的快速回复

标签: apache mod-rewrite url-rewriting


【解决方案1】:

语法不太正确。将您的条件和规则更改为:

RewriteCond %{QUERY_STRING} link_source=email
RewriteRule ^ http://dev1.domain.net:12080/m?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-25
    • 2019-12-19
    • 1970-01-01
    相关资源
    最近更新 更多