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.

link|improve this question

1  
Define "does not work". mod_rewrite doesn't care what browser you use unless there's a RewriteCond on user agent or something. – ceejayoz Nov 5 '11 at 2:40
I thought I clarified pretty well in the OP. Any modern browser other than IE this works: example.com/test.html to www.example.com/test.html but in IE that doesn't work. It will not rewrite the www part. However If I don't put anything after the slash then it does work, example: example.com to www.example.com works in every browser including IE. There is no user agent rewrite conditions. IE simply fails to follow the 301 redirect properly. – morrty Nov 5 '11 at 16:55
The .htaccess rules you've provided cannot cause IE to do something different than another browser. Something else is going on. – ceejayoz Nov 5 '11 at 17:00
@ceejayoz: this is not a .htaccess but you're right: it can't be a browser problem unless morrty didn't give the whole rewrite rules. – Olivier Pons Nov 5 '11 at 21:19
@Olivier Pons: I assure you that the only thing I changed was our WAN IP address in the OP and the root domain to example.com, everything else is in its full. I guess I'll just deal with this behaviour. It's just weird that IE is the only browser doing this. I too doubt that anything I'm doing is affecting the browser but perhaps IE has always had this behaviour? – morrty Nov 7 '11 at 14:23
show 9 more comments
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.