Forum Moderators: phranque

Message Too Old, No Replies

Rewrite and Browsermatch redirect?

How to redirect on both browsermatch and remote-IP?

         

Cees

12:00 pm on Jan 22, 2008 (gmt 0)

10+ Year Member



I am using a rewrite rule based on the remote address of a client:

RewriteCond %{REMOTE_ADDR} 123.123.123.123
RewriteRule .* http://www.example.com/ [R=301,L]

Now if someone with ip: 123.123.123.123 connects, he wil be redirected to http://www.example.com

This works!

But if I want to redirect 123.123.123.123 only when he is using internet-explorer and leave him non-redirected when he is using for example firefox, how can I combine this with a "Browsermatch"?

Any hints please?

[edited by: Cees at 12:48 pm (utc) on Jan. 22, 2008]

jdMorgan

2:16 pm on Jan 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add another RewriteCond in there, testing HTTP_USER_AGENT

Note that further exclusions are required, since otherwise *all* URLs would be redirected, including those for images, CSS, and JavaScript files.

That is not likely to be what you want. You will probably need to exclude requests that are not for "pages", and also exclude the "real" URL-paths to your directory index files, as shown (this code supports .htm, .hmtl, .shtm, .shtml, .php, and .php1 through .php9).


RewriteCond $1 \.(s?html?¦php[1-9]?)$
RewriteCond $1 !/?index\.(s?html?¦php[1-9]?)$
RewriteCond %{REMOTE_ADDR} ^123\.123\.123\.123$
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[0-9.]+\ \([^)]+\)\ Gecko/20[0-9]{6}\ Firefox/[0-9.]+
RewriteRule (.*) http://www.example.com/ [R=301,L]

Replace the broken pipe "¦" character with a solid pipe before use; Posting on this forum modifies the pipe characters.

Jim

Cees

7:34 pm on Jan 22, 2008 (gmt 0)

10+ Year Member



Thank you Jim, that works fine!