简体   繁体   English

Mod_rewrite:重定向到查询字符串中的URL-从重定向URL的末尾丢弃%3f

[英]Mod_rewrite: Redirect to URL in query string - discard %3f from end of redirected URL

I have an .htaccess rewrite rule which takes incoming requests of the form: 我有一个.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

What I want to do is have the rule extract the value of the url key and redirect to its value, ergo: 我想做的是让规则提取url键的值并重定向到它的值ergo:

OUT 1) http://take.me/
OUT 2) http://take.me/another/path/file.htm?key1=val1&key2=val2

The following condition and rule works: 以下条件和规则适用:

RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^index\.htm$ %1? [R,L]`

However in the case of OUT 2 I'm finding that the resultant URL seen in the browser address bar is: 但是,在OUT 2的情况下,我发现在浏览器地址栏中看到的结果URL为:

http://take.me/another/path/file.htm?key1=val1&key2+val2%3f

So the problem is that a %3f (percent encoded question mark) is appended to the resultant URL. 因此,问题在于将%3f (百分比编码的问号)附加到结果URL。 The problem is caused by the use of the ? 问题是由使用? in the RewriteRule, but I need that so that the original query string is discarded. 在RewriteRule中,但是我需要这样做,以便丢弃原始查询字符串。 I do not know if the %3f will cause problems, so to be on the safe side I would like to eliminate it. 我不知道%3f是否会引起问题,因此为了安全起见,我想消除它。 We're using Apache 2.2.22 so no Query String Discard [QSD] option unfortunately. 我们正在使用Apache 2.2.22,因此不幸的是没有查询字符串丢弃[QSD]选项。

Is there a way to eliminate the %3f while maintaining the function of the rule? 有没有办法在维持规则功能的同时消除%3f

You can use this rule with NE flag which means no escaping resulting URL: 您可以将此规则与NE标志一起使用,这意味着no escaping结果URL:

RewriteCond %{THE_REQUEST} index\.htm\?url=(\S+) [NC]
RewriteRule index\.htm$ %1? [L,R=302,NC,NE]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM