你能解释一下你为什么要做这个令人费解的事情吗?你想达到什么目的?一旦你回答了这个问题,你可能不需要知道你想的那么多。
与此同时,这里有一些信息。一个 URL 实际上由多个部分组成
http: - the "scheme" or protocol used to access the resource. "HTTP", "HTTPS",
"FTP", etc are all examples of a scheme. There are many others
// - separates the protocol from the host (server) address
myserver.org - the host. The host name is looked up against a DNS (Dynamic Name Server)
service and resolved to an IP address - the "phone number" of the machine
which can serve up the resource (like "98.139.183.24" for www.yahoo.com)
www.myserver.org - the host with a prefix. Sometimes the same domain (`myserver.org`)
connects multiple servers (or ports) and you can be sent straight to the
right server with the prefix (mail., www., ftp., ... up to the
administrators of the domain). Conventionally, a server that serves content
intended for viewing with a browser has a `www.` prefix, but there's no rule
that says this must be the case.
:8080/ - sometimes, you see a colon followed by up to five digits after the domain.
this indicates the PORT on the server where you are accessing data
some servers allow certain specific services on just a particular port
they might have a "public access" website on port 80, and another one on 8080
the https:// protocol defaults to port 443, there are ports for telnet, ftp,
etc. Add these things only if you REALLY know what you are doing.
/the/pa.th/ this is the path relative to DOCUMENTROOT on the server where the
resource is located. `.` characters are legal here, just as they are in
directory structures.
file.html
file.php
file.asp
etc - usually the resource being fetched is a file. The file may have
any of a great number of extensions; some of these indicate to the server that
instead of sending the file straight to the requester,
it has to execute a program or other instructions in this file,
and send the result of that
Examples of extensions that indicate "active" pages include
(this is not nearly exhaustive - just "for instance"):
.php = contains a php program
.py = contains a python program
.js = contains a javascript program
(usually called from inside an .htm or .html)
.asp = "active server page" associated with a
Microsoft Internet Information Server
?something=value&somethingElse=%23othervalue%23 传递给服务器的参数可以显示在 URL 中。这可以用来传递参数、表单中的条目等。任何字符都可以在这里传递——包括“.”、“&”、“/”……但你不能只在你的字符串中写这些字符...
有趣的来了。
URL 不能包含某些字符(实际上不少)。为了解决这个问题,存在一种称为“转义”角色的机制。通常,这意味着将字符替换为十六进制等效字符,并以%
符号为前缀。因此,例如,您经常会看到表示为 %20 的空格字符。你可以在这里找到一个方便的清单
有许多函数可用于将 URL 中的“非法”字符自动转换为“合法”值。
要确切了解什么是允许的,什么是不允许的,你真的需要回到原来的规范。参见例如
http://www.ietf.org/rfc/rfc1738.txt
http://www.ietf.org/rfc/rfc2396.txt
http://www.ietf.org/rfc/rfc3986.txt
我按时间顺序列出它们——最后一个是最近的。
但我重复我的问题——你在这里真正想做什么,为什么?