大网数据广告活动
网站运营与故障问答

Should query string parameter values in a URI have single quotes around them?

· 52CE 我爱测

I'm passing variables through the URI string, like this: example.com?a=first&b=second Everything works as intended, but when I pass the source code through the W3 validator, it's flagging them as errors. When I quote the variable…

问题原文

原帖链接 · user58934 · CC BY-SA 3.0

I'm passing variables through the URI string, like this:

example.com?a=first&b=second

Everything works as intended, but when I pass the source code through the W3 validator, it's flagging them as errors. When I quote the variables, like this:

example.com?a='first'&b='second'

they do not get flagged. I've never seen a website do this, but is that the proper way to pass these variables? I could not find any source that recommends quoting them in the URI.

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

<a href="link.php?a=first&b=second">Click here!</a>

The only thing that might get flagged in that anchor is the unencoded &. The & should be HTML encoded. ie. &amp; (in order to avoid potential conflict). URL parameters certainly should not be quoted as a general rule.

The URL, by its very nature, is all a "string", so quoting URL parameter values for the sake of it does not make sense, unless you explicitly needed this for your script (although this should probably be avoided, as it just adds clutter). If you quote a URL parameter value then the quotes themselves become part of the value, they do not delimit the value itself.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2015-12-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。