如何在mod_rewrite中解映射QUERY_STRING? [英] How to unescape QUERY_STRING in mod_rewrite?

查看:249
本文介绍了如何在mod_rewrite中解映射QUERY_STRING?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

现在我想在apache2中使用mod_rewrite模块重定向网址。

Now I want to use mod_rewrite module in apache2 to redirect url.

重写规则如下所示:

RewriteCond %{QUERY_STRING} ^url=(.+)$
RewriteRule ^/redir$ %1 [R=301,L]

然而,当http://website.com/ redir?url = http%3A%2F%2Fwww.google.com输入,mod_rewrite模块不能unecsape的url参数http%3A%2F%2Fwww.google.com,有没有办法解决这个问题?

However, when http://website.com/redir?url=http%3A%2F%2Fwww.google.com is input, the mod_rewrite module cannot unecsape the url parameter http%3A%2F%2Fwww.google.com, is there any method to resolve this problem?

推荐答案

RewriteMap unescape int:unescape

RewriteCond %{QUERY_STRING} ^url=(.+)$
RewriteRule ^/redir$ ${unescape:%1} [R=301,L]

Apache允许您从不同类型的外部源定义自定义重写映射。例如,如果要将 / users /<某些别名> 重写为 / users /< full name> ,您可以有一个指定别名/名称对的文本文件,以及使用该映射翻译URL的别名部分的重写规则。

Apache lets you define custom rewrite mappings from different types of external sources. For example, if you wanted to rewrite /users/<some alias> to /users/<full name>, you could have a text file that specified alias/name pairs, and a rewrite rule that translated the "alias" part of the URL using that mapping.

映射可以来自多种类型的来源。别名/名称示例是标准纯文本( txt )类型。

Mappings can come from multiple types of sources. The alias/name example is the standard plain text (txt) type.

RewriteMap 还可以映射到少量特殊的内部源( int )。他们只是将值传递给内部的Apache函数并返回结果。它们是:

RewriteMap also lets you map to a handful of special internal sources (int). They just pass the value to an internal Apache function and return the result. They are:


  • toupper :将键转换为所有大写。 li>
  • tolower :将密钥转换为所有小写。

  • escape :将密钥中的特殊字符转换为十六进制编码。

  • unescape :将十六进制编码关键回到特殊字符。

  • toupper: Converts the key to all upper case.
  • tolower: Converts the key to all lower case.
  • escape: Translates special characters in the key to hex-encodings.
  • unescape: Translates hex-encodings in the key back to special characters.

unescape 是你正在看的for。

unescape is what you're looking for.

更多信息可以在 mod_rewite文档

这篇关于如何在mod_rewrite中解映射QUERY_STRING?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆