2

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"

J-D
  • 737
  • 1
  • 12
  • 27

1 Answers1

1

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]

Panama Jack
  • 24,158
  • 10
  • 63
  • 95
  • Does't work... The problem is the rewriteCond ... It contains the normal browser string along with the prefix ABC .. refer to my original post for the usr agent String.. – J-D Feb 14 '14 at 08:57
  • I understand that. That should work for ABC, Try adding the NC to the end as in my update. Are you sure you string has that ABC in it? – Panama Jack Feb 14 '14 at 14:56