J-D
J-D

Reputation: 774

.htaccess redirecting based on User agent

I am not great at writing regex's for .htaccess redirection but I managed to write this for redirecting basedon useragent.. My useragent String will contain a custom string at the end.. Let's just call this ABC.

RewriteCond %{HTTP_USER_AGENT}  ^.*ABC$
RewriteRule ^(.*)index\.php$ /$1?&mode=test&app=true  [R=301,L]

However, though I am pretty sure that the user-agent request header contains the string. I cannot manage to get it redirected even to a different domain. Pretty sure both the lines are wrong.. the first by maybe 10% and the second by a 50%.

Can someone help me understand how to fix this?

Additional Data "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0 ABC"

Upvotes: 2

Views: 2761

Answers (1)

Panama Jack
Panama Jack

Reputation: 24448

Try this and see if this works for you.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ABC [NC]
RewriteRule ^(.+) $1?mode=test&app=true [L]

If you want the query string to also show along with the URL in the address bar then change [L] to [R=301,L]

Upvotes: 1

Related Questions