无法访问 rawurlencoded UTF-8 URL
我有一个共享托管帐户,我正在使用 Filezilla 连接到服务器。
在 public_html/items/
文件夹下,有很多子文件夹,它们的文件夹名称是使用 PHP rawurlencode
函数编码的,如下所示:
apple
banana
orange
%E6%BC%A2%E5%A0%A1%E9%A3%BD
%E8%96%AF%E6%A2%9D
问题是,当我访问名称中包含非ASCII字符(例如中文字符)的文件夹下的文件。
这意味着我可以访问如下 URL: http://my-domain.com/items/apple/index.html
但不是: http:// my-domain.com/items/%E6%BC%A2%E5%A0%A1%E9%A3%BD/index.html
这可能是什么类型的问题?
非常感谢大家。
I have a shared hosting account and I am using Filezilla to connect to the server.
Under the public_html/items/
folder, there are many subfolders and their folder names are encoded using PHP rawurlencode
function, like these:
apple
banana
orange
%E6%BC%A2%E5%A0%A1%E9%A3%BD
%E8%96%AF%E6%A2%9D
The problem is that I get 404 error when I access the files under the folders whose names contain non-ASCII characters (e.g. chinese characters).
This means I can access URL like this one:
http://my-domain.com/items/apple/index.html
But not:
http://my-domain.com/items/%E6%BC%A2%E5%A0%A1%E9%A3%BD/index.html
What kind of a problem could this possibly be?
Many thanks to you all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果文件夹包含物理 urlencoded 名称,那么您需要确保这些名称本身在您的 url 中进行 urlencoded。事实上,任何时候您从任何“不受控制”的、可能 url 不安全的元素创建 URL 时,都必须对这些元素进行 urlencode。
因此,如果您有一个名为
%E8%96%AF%E6%A2%9D
的目录,您可以在 URL 中使用
%25E8%2596%25AF%25E6%25A2%259D 引用它 很漂亮
,不是吗?
另一种看待这个问题的方法是,当您使用现有的 urlencoded URL 时,服务器实际尝试解析的是 /items/汉堡饱/index.html
If the folders contain physically urlencoded names, then you'll need to ensure these names are themselves urlencoded in your urls. In fact, anytime you create a URL from any 'uncontrolled', potentially url-unsafe elements, you must urlencode those elements.
Thus if you have a directory named
%E8%96%AF%E6%A2%9D
You would refer to it in a URL with
%25E8%2596%25AF%25E6%25A2%259D
Pretty, isn't it?
Another way of looking at this is that when you use your existing urlencoded URL, what the server actually tries to resolve is /items/漢堡飽/index.html