Alexandre Khoury
Alexandre Khoury

Reputation: 4022

Redirect non-IE users in htaccess

I wrote

RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
RewriteRule .* /IE [R=403,L]

to redirect all ie users to the folder IE.

Then I tried

RewriteCond %{HTTP_USER_AGENT} !.*MSIE.*
RewriteCond %{HTTP_HOST} /IE
RewriteRule .* 404.html [R=404,L]

But it didn't work.

How can I make it work?

Upvotes: 0

Views: 115

Answers (2)

Oussama Jilal
Oussama Jilal

Reputation: 7739

The R flag only supports codes between 300 and 400, if you want to through a 403 Forbidden error, use the F flag, if you want to through a 404 Not found error, just redirect users to a non existent page.

Edit :

Try this :

RewriteCond %{HTTP_USER_AGENT} !MSIE
RewriteRule ^IE unexistantpage.html [L]

Or if you want to make it forbidden then :

RewriteCond %{HTTP_USER_AGENT} !MSIE
RewriteRule ^IE - [F,L]

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143866

You are using the wrong var. %{HTTP_HOST} matches against the hostname, not the folder. I think you want something like this:

RewriteCond %{HTTP_USER_AGENT} !.*MSIE.*
RewriteRule ^/?IE /404.html [R=404,L]

Note that the R=404 forces a 404 response, it doesn't actually redirect you anywhere.

Upvotes: 0

Related Questions