Apache:为什么 IE 上的 .htaccess 将非拉丁字符 URL 重写为 urlencode?怎么解决呢?

发布于 2024-10-16 10:10:20 字数 459 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巴黎盛开的樱花 2024-10-23 10:10:20

似乎 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

残月升风 2024-10-23 10:10:20

@Pekka:是的。在最新的浏览器上,任何 URL 都采用 UTF-8 编码。他们将domain.com//контакты 重写为domain.com/контакты,就像例外一样。

据我所知,这并不完全正确,这可能是它对您不起作用的原因。

新浏览器真正所做的是,它们以原生形式контакты向您显示URL,但内部仍然以百分比编码形式发出请求

这似乎是症结所在:您输入一些内容,IE 会识别 Unicode 字符,但随后的 301 重定向会导致(正确的)百分比编码的 URL。现代浏览器会自动“解码”百分比编码的 URL; IE 和旧版浏览器可能不会。

我不知道是否有解决方法。您可以尝试的一件事是让 PHP 脚本进行 URL 重写,并让该脚本重定向到(但无效!)URLDecoded URL:

<?php header("location: http://example.com/контакты"); ?>

不过,我不知道这是否有效。

参考:URL 中的 Unicode 字符

IE相关设置

@Pekka: Yes. On newest browsers any URLs has UTF-8 encoding. And they rewrites domain.com//контакты to domain.com/контакты, like it is excepted to be.

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:

<?php header("location: http://example.com/контакты"); ?>

I have no idea whether this'll work, though.

Reference: Unicode characters in URLs

Related IE setting

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文