带分号的元刷新

发布于 2024-10-19 10:34:46 字数 314 浏览 1 评论 0原文

我在网址中使用分号作为查询字符串分隔符,而不是 and (&)。
我的问题是,当我尝试对查询字符串中带有分号的 url 进行元刷新时,它会将其转换为 %253b。因此,转发时,我无法读取查询字符串参数,因为分隔符不再存在。示例:

http://domain.com/?foo=1;bar=2  

变为:

http://domain.com?foo=1%253bbar=2  

我该如何解决这个问题,以便在进行元刷新时不会翻译分号?

感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玉环 2024-10-26 10:34:46

问题是查询字符串被编码两次,而实际上根本不需要编码。这可能是因为对查询字符串(您没有提及)进行编码和解码的代码需要传统的与号 (&) 查询字符串分隔符,并且可以随意对其他所有内容进行编码。

原始: foo=1;bar=2

第一个编码(分号 → %3B): foo=1%3bbar=2

第二个编码(百分比 → %25): foo=1%253bbar=2

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

空城缀染半城烟沙 2024-10-26 10:34:46

更新

正如评论中指出的, ; 是 url 的有效字符,该字符保留用于 RFC。正如 Danorton 在其自己的答案中指出的那样,问题似乎是 URL 的双重编码。

事实上,如果没有更多有关环境和问题发生时的确切情况的信息,就不可能提供解决方案。

然而,就像我之前的错误答案中所述,我仍然坚持使用 & 作为分隔符的立场。在我看来,使用其他东西会带来问题。

我的“错误”答案

我不认为 ;是 url 的有效字符,因此对我来说它被编码似乎很正常。这是有原因的&已使用,为什么要更改它?

做这样的事情就是自找麻烦。让事情在所有浏览器和操作系统组合上运行已经相当困难了,为什么会让事情变得更加困难呢?

如果您想坚持这一点并且您正在使用 PHP,请查看 urlencode() parse-url()

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()

末が日狂欢 2024-10-26 10:34:46

在 url 中使用单引号可以解决该问题。

<meta http-equiv="refresh" content="0;URL='http://domain.com/?foo=1;bar=2'">   

大多数浏览器(Firefox、Chrome、Safari、Opera)可能会重定向到不带引号的完整 url atm,但 Internet Explorer(IE10 也是如此)将丢弃第二个分号之后不带单引号的部分。


Uri 语法 RFC3986

W3C-Recommendation

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

W3C-Recommendation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文