即使在使用urlencode,URL中的&符之后的数据也会被剥离 [英] data being stripped off after ampersand in URL even when using urlencode
问题描述
我在要获取请求的URL中传递与号
I am passing ampersands in a URL which go into a get request
例如
http://www.soundshelter.co.uk/label/Hit & Run
我尝试对&以便它是有效的URL
I have tried to urlencode the & so that it is a valid URL
http://www.soundshelter.co.uk/label/Hit%20%26%20Run
,但是在get请求中URL的& Run
部分已被截断.
but the & Run
section of the URL is being cut off in the get request.
我认为这可能与我的mod_rewrite有关
I'm thinking this might have something to do with my mod_rewrite
RewriteRule ^label/([^/]*)$ /index.php?label=$1 [NC]
获取请求是
$label = $_GET['label'];
有什么想法吗?
欢呼
推荐答案
来自 the文档:
'B'(转义反向引用)
'B' (escape backreferences)
Apache必须先对URL进行转义,然后再对它们进行映射,因此反向引用将 在他们被解脱的时候 应用.使用B标志, 中的非字母数字字符 向后引用将被转义.为了 例如,请考虑以下规则:
Apache has to unescape URLs before mapping them, so backreferences will be unescaped at the time they are applied. Using the B flag, non-alphanumeric characters in backreferences will be escaped. For example, consider the rule:
RewriteRule ^(.*)$ index.php?show=$1
这会将/C++
映射到index.php?show=/C++
.但这也会
将/C%2b%2b
映射到index.php?show=/C++
,
因为%2b
已被转义.
使用B
标志,它将改为映射
到index.php?show=/C%2b%2b
.
This will map /C++
to index.php?show=/C++
. But it will also
map /C%2b%2b
to index.php?show=/C++
,
because the %2b
has been unescaped.
With the B
flag, it will instead map
to index.php?show=/C%2b%2b
.
在代理情况下,当 如果提供的话,后端可能会折断 带有未转义的URL.
This escaping is particularly necessary in a proxy situation, when the backend may break if presented with an unescaped URL.
因此,尝试:
RewriteRule ^label/([^/]*)$ /index.php?label=$1 [BNC]
另外,转到您的页面,对我来说,您似乎还遇到了其他PHP问题.我建议您发布更多代码上下文.
Also, having gone to your page, it looks to me like you have further PHP problems. I suggest you post more code context.
这篇关于即使在使用urlencode,URL中的&符之后的数据也会被剥离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!