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)
所有服务器(* nix,Windows等)上的HTML文件的文件名中允许使用哪些字符?我正在寻找适用于所有服务器的“最低标准”。使用:我正在命名一个公开提供的文件(Mysite.com/My-Page.htm)
E.g., space? _ - , etc.
例如,空间? _ - 等
E.g., can I have File-Name.htm, File_Name.htm File Name.htm?
例如,我可以使用File-Name.htm,File_Name.htm文件Name.htm吗?
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).
显然,这需要适用于所有服务器和浏览器。 (IIRC,名称受服务器限制而不是浏览器,但我可能错了)。
6 个解决方案
#1
19
What characters are allowed in filenames for HTML files on servers?
服务器上的HTML文件的文件名中允许哪些字符?
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.
这完全取决于服务器。 HTTP本身允许任何字符,包括控制字符和非ASCII字符,只要它们在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.
在Unix服务器上,您不能使用'/'或零字节。 (如果你可以使用它们,它们分别在URL中显示为'%2F'和'%00'。)你也不能拥有特定的文件名'。'或'..',或空字符串。
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).
在Windows服务器上,您具有Unix服务器的所有限制,另外您也不能使用任何\ /:*?“<> |或控制字符1-31,并且您不能使用前导或尾随点或空格,您将难以使用任何遗留设备文件名(CON,PRN,COM1等等)。
This is nothing to do with HTTP; just how filenames work on Windows, which is complicated.
这与HTTP无关;文件名如何在Windows上运行,这很复杂。
can I have File-Name.htm, File_Name.htm File Name.htm?
我可以使用File-Name.htm,File_Name.htm文件Name.htm吗?
Certainly. But in the last case you should link to it by URL-encoding the space:
当然。但在最后一种情况下,您应该通过URL编码空间链接到它:
<a href="File%20Name.htm">thingy</a>
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.
浏览器通常会让你离开这个空间,但它并不是真的有效。如果您想避免考虑URL转义,HTML转义和区分大小写的问题,请坚持使用a-z,0-9和下划线。
#2
2
Be sure to eliminate
一定要消除
* . " / \ [ ] : ; | = ,
*。 “/ \ []:; | =,
which are never allowed, due to inconsistencies in file naming conventions standard practice is to use a-z and 0-9 and the underscore character. Space is needful for most users but if you can get away from using it there are parsing issues that improve reliability, you can read rfc's on mime ( multi-part internet mail extensions ) to get a taste of what is involved.
由于文件命名约定不一致,从不允许这样做,标准做法是使用a-z和0-9以及下划线字符。对于大多数用户来说,空间是必需的,但如果您可以远离使用它,那么解决问题可以提高可靠性,您可以阅读mf(多部分互联网邮件扩展)上的rfc来了解所涉及的内容。
No matter what you do, something somewhere is likely to make life difficult - so much so that I now use cryptographic methods to generate random a-z lowercase strings and use those as filenames, embedding the useful info in the file source code.
无论你做什么,某个地方的东西都可能让生活变得困难 - 以至于我现在使用加密方法生成随机的a-z小写字符串并将它们用作文件名,将有用的信息嵌入到文件源代码中。
Avoid the ampersand at any cost, ...
不惜任何代价避免使用&符号,......
#3
1
If you don't want your filenames to be encoded by the server, you should avoid reserved characters: $&+,/:;=?@ and unsafe characters: space, quotation marks, <>#%{}|\^~[]`
如果您不希望服务器对您的文件名进行编码,则应避免使用保留字符:$&+,/:; =?@和不安全的字符:空格,引号,<>#%{} | \ ^〜 []`
But as the previous answers stated, the web servers should cope with whatever you want to use by encoding the chars.
但正如之前的答案所述,Web服务器应该通过编码字符来处理您想要使用的任何内容。
#4
0
There isn't such a thing as an html filename.
Certain characters have to be encoded in html (eg if used in links) but the allowed characters in the document names will depend on the web server (and possibly the file system on the server).
没有html文件名这样的东西。某些字符必须以html格式编码(例如,如果在链接中使用),但文档名称中允许的字符将取决于Web服务器(可能还有服务器上的文件系统)。
#5
0
Any file name will be URL-encoded so you should be fine. And for the record all three of your file names would work just fine.
任何文件名都将进行URL编码,因此您应该没问题。为了记录,你的所有三个文件名都可以正常工作。
#6
0
I would say a good rule of thumb for filenames for HTML files on ALL servers can be any combination of alphabet (lowercase preferred) and number characters (1 though 9), plus the underline(_), minus(-) or plus(+) characters but no spaces. Also, end the filename with dot html (e.g. filename.html). I personally avoid using underline and plus characters.
我会说所有服务器上的HTML文件的文件名都有一个很好的经验法则可以是字母表(小写首选)和数字字符(1到9)的任意组合,加上下划线(_),减号( - )或加号(+ )字符但没有空格。另外,用点html结束文件名(例如filename.html)。我个人避免使用下划线和加号字符。
#1
19
What characters are allowed in filenames for HTML files on servers?
服务器上的HTML文件的文件名中允许哪些字符?
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.
这完全取决于服务器。 HTTP本身允许任何字符,包括控制字符和非ASCII字符,只要它们在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.
在Unix服务器上,您不能使用'/'或零字节。 (如果你可以使用它们,它们分别在URL中显示为'%2F'和'%00'。)你也不能拥有特定的文件名'。'或'..',或空字符串。
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).
在Windows服务器上,您具有Unix服务器的所有限制,另外您也不能使用任何\ /:*?“<> |或控制字符1-31,并且您不能使用前导或尾随点或空格,您将难以使用任何遗留设备文件名(CON,PRN,COM1等等)。
This is nothing to do with HTTP; just how filenames work on Windows, which is complicated.
这与HTTP无关;文件名如何在Windows上运行,这很复杂。
can I have File-Name.htm, File_Name.htm File Name.htm?
我可以使用File-Name.htm,File_Name.htm文件Name.htm吗?
Certainly. But in the last case you should link to it by URL-encoding the space:
当然。但在最后一种情况下,您应该通过URL编码空间链接到它:
<a href="File%20Name.htm">thingy</a>
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.
浏览器通常会让你离开这个空间,但它并不是真的有效。如果您想避免考虑URL转义,HTML转义和区分大小写的问题,请坚持使用a-z,0-9和下划线。
#2
2
Be sure to eliminate
一定要消除
* . " / \ [ ] : ; | = ,
*。 “/ \ []:; | =,
which are never allowed, due to inconsistencies in file naming conventions standard practice is to use a-z and 0-9 and the underscore character. Space is needful for most users but if you can get away from using it there are parsing issues that improve reliability, you can read rfc's on mime ( multi-part internet mail extensions ) to get a taste of what is involved.
由于文件命名约定不一致,从不允许这样做,标准做法是使用a-z和0-9以及下划线字符。对于大多数用户来说,空间是必需的,但如果您可以远离使用它,那么解决问题可以提高可靠性,您可以阅读mf(多部分互联网邮件扩展)上的rfc来了解所涉及的内容。
No matter what you do, something somewhere is likely to make life difficult - so much so that I now use cryptographic methods to generate random a-z lowercase strings and use those as filenames, embedding the useful info in the file source code.
无论你做什么,某个地方的东西都可能让生活变得困难 - 以至于我现在使用加密方法生成随机的a-z小写字符串并将它们用作文件名,将有用的信息嵌入到文件源代码中。
Avoid the ampersand at any cost, ...
不惜任何代价避免使用&符号,......
#3
1
If you don't want your filenames to be encoded by the server, you should avoid reserved characters: $&+,/:;=?@ and unsafe characters: space, quotation marks, <>#%{}|\^~[]`
如果您不希望服务器对您的文件名进行编码,则应避免使用保留字符:$&+,/:; =?@和不安全的字符:空格,引号,<>#%{} | \ ^〜 []`
But as the previous answers stated, the web servers should cope with whatever you want to use by encoding the chars.
但正如之前的答案所述,Web服务器应该通过编码字符来处理您想要使用的任何内容。
#4
0
There isn't such a thing as an html filename.
Certain characters have to be encoded in html (eg if used in links) but the allowed characters in the document names will depend on the web server (and possibly the file system on the server).
没有html文件名这样的东西。某些字符必须以html格式编码(例如,如果在链接中使用),但文档名称中允许的字符将取决于Web服务器(可能还有服务器上的文件系统)。
#5
0
Any file name will be URL-encoded so you should be fine. And for the record all three of your file names would work just fine.
任何文件名都将进行URL编码,因此您应该没问题。为了记录,你的所有三个文件名都可以正常工作。
#6
0
I would say a good rule of thumb for filenames for HTML files on ALL servers can be any combination of alphabet (lowercase preferred) and number characters (1 though 9), plus the underline(_), minus(-) or plus(+) characters but no spaces. Also, end the filename with dot html (e.g. filename.html). I personally avoid using underline and plus characters.
我会说所有服务器上的HTML文件的文件名都有一个很好的经验法则可以是字母表(小写首选)和数字字符(1到9)的任意组合,加上下划线(_),减号( - )或加号(+ )字符但没有空格。另外,用点html结束文件名(例如filename.html)。我个人避免使用下划线和加号字符。