Forum Moderators: phranque

Message Too Old, No Replies

Redirect Entire IP Range

         

boxfan

5:21 pm on Jan 10, 2008 (gmt 0)

10+ Year Member



Hello,

I am trying to redirect an entire IP range using Apache 1.3

I can use this on my server with Apache 2

ReWriteCond %{REMOTE_ADDR} 1
ReWriteRule .* /cnn.html [L]

Which redirects all IP addresses that begin with the number 1

But this does not work on my server with Apache 1.3.

How can I redirect all users with an IP address that begins with 1 in Apache 1.3?

Thanks

wilderness

9:29 pm on Jan 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



the "begin with" chracter is ^, however your asking for trouble that perhaps you don't clearly understand?

Ex:
1)your missing 001 and 01[0-9].

2) your getting 1[0-9][0-9] which is 199 ranges in the Class A times 255 ranges in the Class B times 255 ranges in the Class C times 255 ranges in the Class D

The latter is quite a large range of visitors to take out (even for my sinister tastes)!

boxfan

9:51 pm on Jan 10, 2008 (gmt 0)

10+ Year Member



Ok, I see, So what would the redirect look like to redirecting all IP addresses that begin with 1?

jdMorgan

10:14 pm on Jan 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually the rule posted above internally rewrites all access requests from all IP addresses that contain the character "1" (in any position) to a local file called /cnn.html, so this rule blocks even more addresses than the analysis for an anchored pattern above would indicate. So, it's not an external redirect, and it rewrites requests from far more IP addresses than you might expect.

In addition, this code would cause an 'infinite' rewriting loop, rewriting /cnn.html to itself until the maximum internal rewrite limit was reached.

The proper code --if I understand your intent-- to externally redirect requests from IP addresses beginning with "1." to the /cnn.html file would be:


RewriteCond %{REMOTE_ADDR} ^1\.
RewriteCond $1 !^cnn\.html$
RewriteRule (.*) http://www.example.com/cnn.html [R=302,L]

This will redirect requests from "only" the 16,646,144 (16.7 million) individually-routable addresses in the range from 1.0.0.1 to 1.255.255.254

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Flush your browser cache completely before testing any changes to your code.

Jim

[edited by: jdMorgan at 10:16 pm (utc) on Jan. 10, 2008]

boxfan

11:21 pm on Jan 10, 2008 (gmt 0)

10+ Year Member



Actually I am looking to move all IP addresses beginning with the number 1. So 1, 11, 100, 150, etc.

So would it be something like

RewriteCond %{REMOTE_ADDR} ^1([0-9]¦[0-9]¦[0-9])\.
RewriteCond $1!^cnn\.html$
RewriteRule (.*) http://www.example.com/cnn.html [R=302,L]

Thanks

wilderness

11:43 pm on Jan 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{REMOTE_ADDR} ^1([0-9]¦[0-9]¦[0-9])\.

What you have is a thrice repeat of the same range.

To obtian what you desire? (against better judgement).

# 1, 10-19, 100-199 ranges of Class A
RewriteCond %{REMOTE_ADDR} ^(1¦1[0-9]¦1[0-9][0-9])\.

And I'm not all that positive about the first instance of the "1". (I'd feel much safer modifying that to [01]

In addition, you need to make corrections for the forums broken use of the pipe symbol, before using live.

Don

jdMorgan

1:30 am on Jan 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you really want to redirect all IPs starting with a "1" then it's simply:

RewriteCond %{REMOTE_ADDR} ^1
RewriteCond $1 !^cnn\.html$
RewriteRule (.*) http://www.example.com/cnn.html [R=302,L]

Regular expressions are powerful -- Use the power. :)

Jim

boxfan

5:37 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



Thanks for all the help on this topic.