Apache:为什么 IE 上的 .htaccess 将非拉丁字符 URL 重写为 urlencode?怎么解决呢?
Apache:为什么在 IE
上 .htaccess 将非拉丁字符 URL 重写为 urlencode
?怎么解决呢?
domain.com//контакты 重写为domain.com/%D0%BA%D0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D1%8B
RewriteEngine On
# Rewrite multiple slashes with single slash after domain
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,NE,L]
Apache: Why on IE
.htaccess rewrites non Latin character URLs to urlencode
? How to solve it?
domain.com//контакты rewrites to domain.com/%D0%BA%D0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D1%8B
RewriteEngine On
# Rewrite multiple slashes with single slash after domain
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,NE,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎 IE 仍然没有解决方案,这取决于浏览器地址栏编码。
就像 Chrome 12 显示 UTF-8 url domain.com/контакты 一样,但是在 Ctr+C、Ctr+P 上,您将获得 Unicode url http://domain.com/%D0%BA%D0%BE%D0%BD %D1%82%D0%B0%D0%BA%D1%82%D1%8B
Seems there still are no solution for IE and it depends of browser address-bar encoding.
Like Chrome 12 shows UTF-8 url domain.com/контакты, but on Ctr+C, Ctr+P you will get Unicode url http://domain.com/%D0%BA%D0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D1%8B
据我所知,这并不完全正确,这可能是它对您不起作用的原因。
新浏览器真正所做的是,它们以原生形式
контакты
向您显示URL,但内部仍然以百分比编码形式发出请求。这似乎是症结所在:您输入一些内容,IE 会识别 Unicode 字符,但随后的 301 重定向会导致(正确的)百分比编码的 URL。现代浏览器会自动“解码”百分比编码的 URL; IE 和旧版浏览器可能不会。
我不知道是否有解决方法。您可以尝试的一件事是让 PHP 脚本进行 URL 重写,并让该脚本重定向到(但无效!)URLDecoded URL:
不过,我不知道这是否有效。
参考:URL 中的 Unicode 字符
IE相关设置
As far as I know, this is not entirely correct and this may be the reason why it doesn't work for you.
What new browsers are really doing is they show you the URL in its native form
контакты
, but internally still make the request in percent encoded form.This seems to be the crux: You type something in, IE recognizes the Unicode characters, but the subsequent 301 redirect leads to a (correct) percent encoded URL. A modern browser will automatically "decode" the percent encoded URL; IE and older browsers might not.
I don't know whether there is a workaround for this. One thing you could try is have a PHP script do the URL rewriting, and have that script redirect to the (however invalid!) URLDecoded URL:
I have no idea whether this'll work, though.
Reference: Unicode characters in URLs
Related IE setting