Web 服务器文件名的合法/允许字符是什么? [英] What are the Legal / Allowed characters for web server file names on?

查看:42
本文介绍了Web 服务器文件名的合法/允许字符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有服务器(*nix、Windows 等)上的 HTML 文件的文件名中允许使用哪些字符?我正在寻找适用于所有服务器的最低公分母".用途:我正在命名一个要公开提供的文件 (Mysite.com/My-Page.htm)

What characters are allowed in filenames for HTML files on ALL servers (*nix, Windows, etc.) ? I'm looking for the "lowest common denominator" that will work on all servers. USE: I'm naming a file to be served up publicly (Mysite.com/My-Page.htm)

例如,空间?_ - 等

E.g., space? _ - , etc.

例如,我可以有 File-Name.htm、File_Name.htm File Name.htm 吗?

E.g., can I have File-Name.htm, File_Name.htm File Name.htm?

显然,这需要适用于所有服务器和浏览器.(IIRC,名称受服务器而不是浏览器的限制,但我可能错了).

Obviously, this needs to work with all servers and browsers. (IIRC, the name is limited by the server not the browser, but I could be wrong).

推荐答案

服务器上 HTML 文件的文件名中允许使用哪些字符?

What characters are allowed in filenames for HTML files on servers?

这完全取决于服务器.HTTP 本身允许任何字符,包括控制字符和非 ASCII 字符,只要它们在 URL 中被请求时进行适当的 % 编码即可.

That totally depends on the server. HTTP itself allows any character at all, including control characters and non-ASCII characters, as long as they are suitably %-encoded when requested in a URL.

在 Unix 服务器上,您不能使用/"或零字节.(如果您可以使用它们,它们将分别作为%2F"和%00"出现在 URL 中.)您也不能使用特定的文件名."或..",或空字符串.

On a Unix server you cannot use ‘/’ or the zero byte. (If you could use them, they'd appear in the URL as ‘%2F’ and ‘%00’ respectively.) You also can't have the specific filenames ‘.’ or ‘..’, or the empty string.

在 Windows 服务器上,您具有 Unix 服务器的所有限制,而且您也不能使用任何 \/:*?"<>| 或控制字符 1-31并且您不能有前导或尾随点或空格,并且您将难以使用任何旧设备文件名(CON、PRN、COM1 等).

On a Windows server you have all the limitations of a Unix server, plus you also can't use any of \/:*?"<>| or control characters 1-31 and you can't have leading or trailing dot or spaces, and you'll have difficulty using any of the legacy device filenames (CON, PRN, COM1 and many more).

这与 HTTP 无关;文件名在 Windows 上的工作原理,这是复杂.

This is nothing to do with HTTP; just how filenames work on Windows, which is complicated.

我可以有 File-Name.htm、File_Name.htm File Name.htm 吗?

can I have File-Name.htm, File_Name.htm File Name.htm?

当然.但在最后一种情况下,您应该通过对空格进行 URL 编码来链接到它:

Certainly. But in the last case you should link to it by URL-encoding the space:

<a href="File%20Name.htm">thingy</a>

浏览器通常会让你离开空间,但这不是真的有效.如果您想避免考虑 URL 转义、HTML 转义和区分大小写的问题,请坚持使用 a–z、0–9 和下划线.

Browsers will usually let you get away with leaving the space in, but it's not really valid. If you want to avoid having to think about URL-escaping, HTML-escaping and case-sensitive issues, stick to a–z, 0–9 and underscore.

这篇关于Web 服务器文件名的合法/允许字符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆