用 Apache2 替换查询字符串中的键值对
Replace key-value pair in query string with Apache2
我正在尝试在我的 URL 查询字符串中设置一个简单的替换。
我的查询字符串中有一个绝对路径我想用自定义字符串替换。
FROM http://acme.com/a/path?file=DIR/this.file&foo=2
TO http://acme.com/a/path?file=/long/absolute/path/to/this.file&foo=2
这些是我的指示:
# [sudo a2enmod rewrite]
RewriteCond %{QUERY_STRING} ^(.*)file=DIR(.*)$
RewriteRule ^/a/path /a/path?%1file=/long/absolute/path/to%2
这样的配置,替换不行,DIR
通过。
我在我的 Apache2 配置中配置了 LogLevel
到 trace1
,但我在 access.log
中什么也没有得到,在 error.log
中也没有有用的反馈。
问题是:
参考文献:
这对我有用(我添加了标志 R 和 L):
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)file=DIR(.*)$
RewriteRule ^/a/path /a/path?%1file=/long/absolute/path/to%2 [R,L]
我正在尝试在我的 URL 查询字符串中设置一个简单的替换。
我的查询字符串中有一个绝对路径我想用自定义字符串替换。
FROM http://acme.com/a/path?file=DIR/this.file&foo=2
TO http://acme.com/a/path?file=/long/absolute/path/to/this.file&foo=2
这些是我的指示:
# [sudo a2enmod rewrite]
RewriteCond %{QUERY_STRING} ^(.*)file=DIR(.*)$
RewriteRule ^/a/path /a/path?%1file=/long/absolute/path/to%2
这样的配置,替换不行,DIR
通过。
我在我的 Apache2 配置中配置了 LogLevel
到 trace1
,但我在 access.log
中什么也没有得到,在 error.log
中也没有有用的反馈。
问题是:
参考文献:
这对我有用(我添加了标志 R 和 L):
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)file=DIR(.*)$
RewriteRule ^/a/path /a/path?%1file=/long/absolute/path/to%2 [R,L]