【发布时间】:2016-05-12 07:03:55
【问题描述】:
我有一个 .htaccess 重写规则,它接受以下形式的传入请求:
IN 1) http://some.domain.com/path/to/index.htm?url=http://take.me/
IN 2) http://some.domain.com/path/to/index.htm?url=http://take.me/another/path/file.htm?key1=val1&key2+val2
我想要做的是让规则提取 url 键的值并重定向到它的值,ergo:
OUT 1) http://take.me/
OUT 2) http://take.me/another/path/file.htm?key1=val1&key2=val2
以下条件和规则有效:
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^index\.htm$ %1? [R,L]`
但是在 OUT 2 的情况下,我发现在浏览器地址栏中看到的结果 URL 是:
http://take.me/another/path/file.htm?key1=val1&key2+val2%3f
所以问题是%3f(百分比编码的问号)附加到生成的 URL。该问题是由在 RewriteRule 中使用 ? 引起的,但我需要这样才能丢弃原始查询字符串。我不知道%3f 是否会引起问题,所以为了安全起见,我想消除它。我们使用的是 Apache 2.2.22,所以遗憾的是没有 Query String Discard [QSD] 选项。
有没有办法在保持规则功能的同时消除%3f?
【问题讨论】:
标签: apache .htaccess mod-rewrite redirect