开发者

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

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%开发者_JAVA技巧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


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.


Try changing your rewrite rule to

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜