redirect on ip adress

Hi there,

I would like to redirect all trafic which does not come from a specified IP to
another URL.

Something like this:
RewriteEngine On
RewriteRule ^(.*)$ http://www.newadress.net/

Any idea if this could be done with a regex instead of .* ?

Thanx for any help,

Merlin
merlin [ Do, 08 September 2005 10:29 ] [ ID #957845 ]

Re: redirect on ip adress

Merlin wrote:
> I would like to redirect all trafic which does not come from a specified
> IP to another URL.
>
> Something like this:
> RewriteEngine On
> RewriteRule ^(.*)$ http://www.newadress.net/

Try something like this:
RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
RewriteRule ^(.*)$ http://www.newadress.net/

This will rewrite all requests that aren't from the specified ip address.

Richard.
Richard Antony Burton [ Do, 08 September 2005 14:02 ] [ ID #957846 ]

Re: redirect on ip adress

Hi,

without the negation it works:
RewriteCond %{REMOTE_ADDR} ^141.62.11.80$

but with negation it does not
RewriteCond %{REMOTE_ADDR} !^141.62.11.80$

I tried to escape the dots but it also did not help. The IP seems to be correct.

Any ideas if the syntax could be different?

Thanx,

Merlin

Richard Antony Burton wrote:
> Merlin wrote:
>
>> I would like to redirect all trafic which does not come from a
>> specified IP to another URL.
>
> >
>
>> Something like this:
>> RewriteEngine On
>> RewriteRule ^(.*)$ http://www.newadress.net/
>
>
> Try something like this:
> RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
> RewriteRule ^(.*)$ http://www.newadress.net/
>
> This will rewrite all requests that aren't from the specified ip address.
>
> Richard.
merlin [ Fr, 09 September 2005 08:37 ] [ ID #959438 ]

Re: redirect on ip adress

Merlin wrote:
> without the negation it works:
> RewriteCond %{REMOTE_ADDR} ^141.62.11.80$
>
> but with negation it does not
> RewriteCond %{REMOTE_ADDR} !^141.62.11.80$

What do you mean it works without the negation, and not with it? Do you
mean that without the negation it does what you want, but in reverse?
i.e. it redirects requests from that address, but not from everywhere
else? What does your rewrite log show? I did test this, and it does work.

> I tried to escape the dots but it also did not help. The IP seems to be
> correct.

Ah yes, good thinking, though that will only stop a few extra possible
matches, not prevent it matching the one it should.

Richard.
Richard Antony Burton [ Fr, 09 September 2005 09:57 ] [ ID #959439 ]

Re: redirect on ip adress

In article <3ocpkpF5b80dU1 [at] individual.net>,
Merlin <ngroups [at] fastmail.fm> wrote:

> Hi,
>
> without the negation it works:
> RewriteCond %{REMOTE_ADDR} ^141.62.11.80$
>
> but with negation it does not
> RewriteCond %{REMOTE_ADDR} !^141.62.11.80$

did you try :

RewriteCond %{REMOTE_ADDR} !=^141.62.11.80$

or

RewriteCond %{REMOTE_ADDR} !(141.62.11.80)

patpro
patpro [ Fr, 09 September 2005 10:17 ] [ ID #959440 ]
Webserver » alt.apache.configuration » redirect on ip adress

Vorheriges Thema: mod_rewrite
Nächstes Thema: Newbie question: Mime type for iso files