Apache mod_rewrite weird behavior in Internet Explorer

Posted by morrty on Server Fault See other posts from Server Fault or by morrty
Published on 2011-11-04T19:44:56Z Indexed on 2011/11/19 1:54 UTC
Read the original article Hit count: 504

I'm attempting to setup redirection for a couple of root domains.

Firstly, here is the code in my httpd-vhosts.conf file:

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

What this does is redirect the root domain of example.com or example2.com or any host other than www to www.example(2).com

The part I'm having a problem with is the RewriteRule itself. the $1 is supposed to match the pattern of the RewriteRule and add it in the substitution. For example: "http://example.com/test.html" should rewrite to "http://www.example.com/test.html"

It works in all modern browsers like it's supposed to except for IE8 or IE9 (I didn't test other IE versions).

In IE, this works: "http://example.com" to "http://www.example.com"

In IE, this does not work: "http://example.com/test.html" to "http://www.example.com/test.html"

Does anyone have an explanation for this behavior?

I hope I've explained it well enough.

Thank you.

© Server Fault or respective owner

Related posts about apache2

Related posts about mod-rewrite