问题
I have semicolon as query string separator in my urls instead of and (&).
My problem is that when I try to do a meta refresh to a url with semicolon in query string it will translate it to %253b instead. So when forwarded, I can't read the query string parameters as the separator is not there anymore. example:
http://domain.com/?foo=1;bar=2
becomes:
http://domain.com?foo=1%253bbar=2
How can I solve this, so it doesn't translate the semicolon when doing a meta refresh?
Grateful for any help!
回答1:
The problem is that the query string is being encoded twice, when it needn’t be encoded at all. This is probably because the code that encodes and decodes the query string (which you don’t mention) is expecting the traditional ampersand (&) query string separator and feels free to encode everything else.
Original: foo=1;bar=2
1st encoding (semicolon → %3B): foo=1%3bbar=2
2nd encoding (percent → %25): foo=1%253bbar=2
回答2:
UPDATE
As pointed in the comments, ;
is a valid character for an url which is reserved for a purpose not specified in the RFC. Like pointed by danorton in its own answer, the problem seems to be a double encoding of the URL.
As it is, it is impossible to provide a solution without more information about the environment and the exact situation when the problem occurs.
However, like stated in my previous wrong answer, I stay on my position concerning the use of &
as a separator. Using something else is asking for problems in my opinion.
my "wrong" answer
I don't think ; is a valid character for an url, so it seems normal to me that it get encoded. There's a reason & is used, why do you want to change that ?
Doing something like this is asking for problems. It's already pretty hard to get things working on all the browsers and OSes combination, why makes things even harder ?
If you want to stick with this and you're using PHP, have a look at urlencode() and parse-url()
回答3:
Using single quotes for the url will fix the issue.
<meta http-equiv="refresh" content="0;URL='http://domain.com/?foo=1;bar=2'">
Most browsers (Firefox, Chrome, Safari, Opera) will probably redirect to the full url atm without the quotes, but Internet Explorer (IE10 too) will discard the part after the second semicolon without the single quotes.
Uri Syntax RFC3986
- Semicolon as separator: http://tools.ietf.org/html/rfc3986#section-3.3
Reserved characters: http://tools.ietf.org/html/rfc3986#appendix-A
: / ? # [ ] @ ! $ & ' ( ) * + , ; =
W3C-Recommendation
- Using meta refresh: http://www.w3.org/TR/WCAG20-TECHS/H76.html
- ";" instead of "&": http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2
来源:https://stackoverflow.com/questions/5124170/meta-refresh-with-semicolon