Forum Moderators: phranque

Message Too Old, No Replies

Redirect based on user agents

         

vygbuyhnmj

1:39 am on May 2, 2007 (gmt 0)

10+ Year Member



I want the browsers Netscape and Opera to be redirected to a specific URL.

My current working .htaccess is below:

Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on

RewriteCond %{REQUEST_URI}!^\/index\.php
RewriteCond %{REQUEST_URI}!^\/template
RewriteRule ^(.*)$ /index.php?mode=$1 [L]

Then I added what I thought would work for Netscape/Opera, but it doesn't redirect the user to the new page.

Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} ^Netscape.*
RewriteRule http://www.example.com/netscape.html [R,L]

RewriteCond %{HTTP_USER_AGENT} ^Opera.*
RewriteRule http://www.example.com/opera.html [R,L]

RewriteCond %{REQUEST_URI}!^\/index\.php
RewriteCond %{REQUEST_URI}!^\/template
RewriteRule ^(.*)$ /index.php?mode=$1 [L]

Where did I go wrong?

jdMorgan

12:38 pm on May 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anchoring on the user-agent strings was incorrect. An explicit RewriteCond is needed to prevent an infinite redirection loop. The RewriteRule pattern was missing (syntax error).

RewriteCond %{HTTP_USER_AGENT} Netscape
RewriteCond %{REQUEST_URI} !^/netscape\.html$
RewriteRule .* http://www.example.com/netscape.html [R=302,L]
#
RewriteCond %{HTTP_USER_AGENT} Opera
RewriteCond %{REQUEST_URI} !^/opera\.html$
RewriteRule .* http://www.example.com/opera.html [R=302,L]

Jim