Apache mod_rewrite 在 Internet Explorer 中的行为异常

Apache mod_rewrite 在 Internet Explorer 中的行为异常

我正在尝试为几个根域设置重定向。

首先,这是我的代码httpd-vhosts.conf文件:

<VirtualHost *:80>

ServerAdmin ****@example.com
ServerName example.com
ServerAlias example2.com

RewriteEngine On
RewriteCond %{HTTP_HOST} !^192\.168\.0\.1$    # This is our WAN IP
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE]

</VirtualHost>

这样做的目的是重定向示例.com或者example2.com或除以下主机之外的任何主机万维网www.example(2).com

我遇到问题的部分是 RewriteRule 本身。1 美元应该与 RewriteRule 的模式匹配并将其添加到替换中。例如:“http://example.com/test.html“ 应重写为 ”http://www.example.com/test.html

它可以在除 IE8 或 IE9 之外的所有现代浏览器中运行(我没有测试其他 IE 版本)。

在 IE 中,此方法有效:“http://example.com“ 到 ”http://www.example.com

在 IE 中,这不起作用:“http://example.com/test.html“ 到 ”http://www.example.com/test.html

有人可以解释这种行为吗?

我希望我已经解释得足够清楚了。

谢谢。

答案1

将此代码放入 htaccess 中为我修复了类似的问题:

BrowserMatch "MSIE [2-8]" nokeepalive downgrade-1.0 force-response-1.0

相关内容