Forum Moderators: phranque

Message Too Old, No Replies

Redirect rules for internet explorer in htaccess

Redirect rules for internet explorer in htaccess

         

awong316

4:08 pm on Jul 3, 2019 (gmt 0)

5+ Year Member



Hi All,

I've been trying to get a way to redirect all users on IE that visit a certain page to a different page in the htaccess.

Below are the fixes I've come up with, but neither of them worked.

This had no effect whatsoever
# BEGIN IE FIX
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*Trident.* [NC]
RewriteRule ^/quote https://www.example.com/custom-inquiry/ [R,L]
RewriteCond %{HTTP_USER_AGENT} .*MSIE.* [NC]
RewriteRule ^/quote https://www.example.com/custom-inquiry/ [R,L]
# END IE FIX

This redirected all users instead of just IE users
# BEGIN IE FIX
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*Trident.* [NC]
Redirect 301 /quote https://www.example.com/custom-inquiry
RewriteCond %{HTTP_USER_AGENT} .*MSIE.* [NC]
Redirect 301 /quote https://www.example.com/custom-inquiry
# END IE FIX

lucy24

4:48 pm on Jul 3, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



#1
htaccess
...
RewriteRule ^/

There's your problem.

#2 mod_alias (Redirect by that name) can't evaluate conditions.

#3 Each module is an island. A RewriteCond will not be applied to a mod_alias Redirect just because the two are physically adjacent in the htaccess file.

not2easy

5:07 pm on Jul 3, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



In case the terminology is not familiar, the mod_alias advice refers to the line that starts with:
Redirect 301
it is ignoring your RewriteCond.


another idea -
RewriteCond %{HTTP_USER_AGENT} .*Trident.* [NC]
and
RewriteCond %{HTTP_USER_AGENT} .*MSIE.* [NC]
can usually be simplified to
RewriteCond %{HTTP_USER_AGENT} (MSIE|Trident) [NC] 
(and/or)

awong316

5:22 pm on Jul 3, 2019 (gmt 0)

5+ Year Member



RewriteCond %{HTTP_USER_AGENT} (MSIE|Trident) [NC]


Would this still need the *asterisk in the front and back of each in order to catch the user agent?

not2easy

6:11 pm on Jul 3, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Would this still need the *asterisk...

No, because the items within parentheses indicate (contains) and by separating the two terms with "|" it means "and/or" so it would be any UA that contains "MSIE" or "Trident" or "MSIE and Trident"

phranque

7:03 pm on Jul 3, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



also note that the [R,L] flag will generate a 302 by default.
if you want a 301 you must use [R=301,L]

lucy24

8:22 pm on Jul 3, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Leading or trailing .* (or .+) are only ever needed if you are capturing. In fact it's possible these forms will take an extra picosecond of server time, because it first grabs the entire string and then says “Oh, oops, I was supposed to leave room for a ‘Trident’”. That sounds like a chewing-gum commercial, but it can't be helped.