data being stripped off after ampersand in URL even when using urlencode

隐身守侯 提交于 2019-12-11 06:55:39

问题


I am passing ampersands in a URL which go into a get request

e.g.

http://www.soundshelter.co.uk/label/Hit & Run

I have tried to urlencode the & so that it is a valid URL

http://www.soundshelter.co.uk/label/Hit%20%26%20Run

but the & Run section of the URL is being cut off in the get request.

I'm thinking this might have something to do with my mod_rewrite

RewriteRule ^label/([^/]*)$ /index.php?label=$1 [NC]

the get request is

$label = $_GET['label'];

Any ideas?

Cheers


回答1:


From the documentation:

'B' (escape backreferences)

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 

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.

This escaping is particularly necessary in a proxy situation, when the backend may break if presented with an unescaped URL.

So, try:

RewriteRule ^label/([^/]*)$ /index.php?label=$1 [BNC]

Also, having gone to your page, it looks to me like you have further PHP problems. I suggest you post more code context.




回答2:


Try changing your rewrite rule to

RewriteRule ^label/([^/]*)$ /index.php?label=$0 [NC]


来源:https://stackoverflow.com/questions/5316795/data-being-stripped-off-after-ampersand-in-url-even-when-using-urlencode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!