Html URL中`%3F`的使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41380916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:11:02  来源:igfitidea点击:

the use of `%3F` in URL

htmlurl

提问by Flummox - don't be evil SE

While moving a website - that I did not build - I have run into the use of %3F.

在移动网站时 - 我没有建立 - 我遇到了使用%3F.

%3Fis the percent-encodedversion of ?.

%3F是 的百分比编码版本?

It seems to be used like this a lot:

它似乎经常这样使用:

<ahref="example%3Flang=1.html">Example</a>

when linking to a file named example_lang=1.html.

当链接到名为example_lang=1.html.

So, I replaced %3Fwith _, and all works again.

所以,我%3F_,替换了所有的工作。

I am missing something here. The old website worked. After being moved, it no longer worked. After the replacement of %3Fto _, the links worked again. Why?

我在这里遗漏了一些东西。旧网站有效。移动后,它不再起作用。替换%3Fto 后_,链接再次起作用。为什么?

回答by sagar

First, you should elaborate your question to understand it better after all If I understood it correctly then this might be the answer.

首先,你应该详细说明你的问题,以便更好地理解它,如果我理解正确,那么这可能就是答案。

"_" is not a reserved URI character.

“_”不是保留的 URI 字符。

As you said that %3F is reserved for "?" then you are absolutely right but if you read the documentation written on wiki states that "_"(underscore) is not a reserved URI character.

正如您所说, %3F 是为“?”保留的。那么您是绝对正确的,但是如果您阅读了写在 wiki 上的文档,就会指出“_”(下划线)不是保留的 URI 字符。

So that for example if the URL for a web page is "example_test.html" then its encoded URL must be "example_test.html" if there is not any mechanism applied on that URL. Now I will take an another example of PHP based web page that may answer your question.

因此,例如,如果网页的 URL 是“ example_test.html”,那么它的编码 URL 必须是“ example_test.html”,如果该 URL 没有应用任何机制。现在我将举另一个基于 PHP 的网页示例,它可以回答您的问题。

In PHP there is a function "str_replace" that is used to replace the string by programmer defined characters or string.

在 PHP 中有一个函数“ str_replace”,用于用程序员定义的字符或字符串替换字符串。

Let assume that I have a page named "example_test.html" and for some xyz reasons I want to change it to "example%3Ftest.html" then I can use

假设我有一个名为“ example_test.html”的页面,出于某些 xyz 原因,我想将其更改为“ example%3Ftest.html”,然后我可以使用

str_replace("%3F","_","<a href='example%3Ftest.html'>Example Test</a>");

str_replace("%3F","_","<a href='example%3Ftest.html'>Example Test</a>");

This function will search for all occurences of "%3F" and replace it with "_" in provided string(here "href=example%3Ftest.html") and output as "href='example_test.html" which is the actual link for my file.

此函数将搜索所有出现的“ %3F”并将其替换为提供的字符串中的“ _”(此处为“ href=example%3Ftest.html”)并输出为“ href='example_test.html”,这是实际链接为我的文件。