不同的行为处理\(反斜杠)在url由FireFox和Chrome [英] Different behaviours of treating \ (backslash) in the url by FireFox and Chrome

查看:365
本文介绍了不同的行为处理\(反斜杠)在url由FireFox和Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

根据我的经验,当我的ubuntu工作站配置在活动目录的域上时,为我创建的用户名是根据到以下模式。

According to my experience when my ubuntu workstation is configured on domain with active directory, the user name created for me was according to the following pattern.


domain_name\user_name

domain_name\user_name


$ b b

在linux上使用apache的 userdir 扩展功能需要在URL中使用用户名才能访问主目录中的public_html。

Using the userdir extensions of apache on linux will require to use user name in the URL in order to access public_html in the home directory.


http:// localhost /〜domain_name \user_name

http://localhost/~domain_name\user_name

问题A:

Chrome转换所有反斜杠 \ '字符到正斜杠 / ,并且生成的网址与之前完全不同,总是显示未找到

Chrome converts all the backslash '\' characters in the URL to forward slash '/' and the resultant url becomes as under that is totally different and always results Not Found.


http:// localhost /〜domain_name / user_name


http://localhost/~domain_name/user_name

Firefox另一方面不会将反斜杠转换为正斜杠,因此对预期目标的http请求由web服务器。

Firefox on the other hand does not convert back slash to forward slash so http request to intended target is served by web server.

Common solution is to encode back slash in %5C.

问题B

如果我们在CSS @import构造中使用类似的路径(在路径中包含 \ ),则css文件作为HTTP Get Request的导入过程会因报告404错误和报告的URL在404错误中缺少 \ 的存在。这意味着 \ 会从网址中删除,然后才会针对其调用GET请求。

If we use a similar path (containing \ in path) in CSS @import construct, the import process of css file as HTTP Get Request is failed by reporting 404 error and the URL reported in the 404 error miss the presence of \ altogether. It means \ is removed from the URL before to invoke GET request against it.

这种行为在Firefox和Chrome中很常见。但是他们有不凡的解决方案

This behavior is common in Firefox and Chrome. But they have uncommon solutions

火狐需求逃回削减在css中导入过程的工作。

Firefox needs escaped back slash to work in css import process.

@import URL(HTTP://本地主机/〜domain_name\\user_name /路径/要/ CSS);

@import url("http://localhost/~domain_name\\user_name/path/to/css");

Chrome平常需要一个编码反斜杠解决方案。

Chrome as usual needs an encoded back slash solution.


@import url(http:// localhost /〜domain_name% 5Cuser_name / path / to / css);

@import url("http://localhost/~domain_name%5Cuser_name/path/to/css");




  • > \ 在网址中?

  • 是否有办法避免在用户名中显示 \

    • What is the unified solutions to deal with \ in URL?
    • Is there a way to avoid a \ to appear in user name?
    • 推荐答案

      在URL中处理反斜杠的统一解决方案是使用%5C。 RFC 2396根本不允许这个字符在URL中(所以任何关于该字符的行为只是错误恢复行为)。 RFC 3986允许它,但是没有被广泛实现,至少因为它不与现有的URL处理器完全兼容。

      The unified solution to deal with backslash in a URL is to use %5C. RFC 2396 did not allow that character in URLs at all (so any behavior regarding that character was just error-recovery behavior). RFC 3986 does allow it, but is not widely implemented, not least because it's not exactly compatible with existing URL processors.

      Chrome,特别是做与IE :假设您在任何时候键入反斜杠时都意味着正斜杠,正如您发现的,因为这是Windows文件路径的作用。

      Chrome, in particular, does the same thing as IE: assumes you meant a forward slash any time you type a backslash, as you discovered, because that's what Windows file paths do.

      这篇关于不同的行为处理\(反斜杠)在url由FireFox和Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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