Forum Moderators: phranque

Message Too Old, No Replies

Help with redirect of specific IPs requesting specific pages

redirect someone viewing a specific subdirectory, from a specific IP

         

LeatherWing

6:29 pm on Feb 20, 2006 (gmt 0)

10+ Year Member



Ok here's my problem
I would like someone comming into a subdirectory of my web, from a specific set of IP addresses, to be redirected to a page of the same name in another directory.

Here's my code:

RewriteCond %{REMOTE_ADDR} ^11\.1\.1\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^11\.11\.11\.1[6-9]$ [OR]
RewriteCond %{REMOTE_ADDR} ^11\.11\.11\.2[0-3]$ [OR]
RewriteCond %{REMOTE_ADDR} ^111\.111\.11\.1[0-7]$
RewriteCond %{REQUEST_URI} ^/Stayout/
RewriteRule (.*) /ViewThis/$1

When I put this in my .httaccess file I get a 500 error. Anyideas on what I'm doing wrong? (Yes there is no [L] on this rule as all requests are redirected through a CGI in latter rules)

jdMorgan

11:34 pm on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LeatherWing,

Welcome to WebmasterWorld!

I don't see anything wrong with that code snippet -- I assume that you have other, already-working rules?

Is there anything useful in your raw server error log when you get the 500 Error?

Perhaps you may have set up an 'infinite' loop, though -- it depends on where this code resides and the relationship between the paths of the other files. You could try adding a loop-killer by excluding the /ViewThis/ path:


RewriteCond %{REMOTE_ADDR} ^11\.1\.1\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^11\.11\.11\.1[6-9]$ [OR]
RewriteCond %{REMOTE_ADDR} ^11\.11\.11\.2[0-3]$ [OR]
RewriteCond %{REMOTE_ADDR} ^111\.111\.11\.1[0-7]$
RewriteCond %{REQUEST_URI} ^/Stayout/
RewriteCond %{REQUEST_URI} !^/ViewThis/
RewriteRule (.*) /ViewThis/$1

Also, you may the the [PT] flag (pass-through) on the rule if your .cgi requires a URL as input, rather than a server filepath.

Jim

LeatherWing

5:24 pm on Feb 23, 2006 (gmt 0)

10+ Year Member



Well that seems to clear up my 500 errors!

Thanks alot!

Now If I get just get my CGI to behave properly.
My CGI program seems to be getting an unaltered REQUEST_URI to the /Stayout directory and processing based on that.

Looks like I might have to code there to recognize the incomming IPs as well.

jdMorgan

8:49 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're on Apache 1.x rather than 2.x, this might be an error in the order of your LoadModule list.

Apache modules are executed in the reverse order of their appearance in the LoadModule list. For example, if your cgi is a PERL script, and if the PERL module appears in the LoadModule list *after* mod_rewrite, then your CGI script will run before mod_rewrite ever gets a chance to execute.

This applies only to Apache 1.x, though; Apache 2.x uses a different priority-resolution method to determine module execution order.

Jim

LeatherWing

3:04 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



BINGO!
$ENV{SERVER_SOFTWARE}=
Apache/1.3.34 (Unix) mod_psoft_traffic/0.1 PHP/4.4.0 mod_ssl/2.8.25 OpenSSL/0.9.6b FrontPage/5.0.2.2635 mod_throttle/3.1.2

Looks like I'm on Apache 1.3

Unfortunalty here's where my novice really shows...What/Where is the LoadModule list. Im useing a hosted site so I'm betting I cant get to it.

jdMorgan

3:25 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, it's in httpd.conf or in one of its subordinate conf.d files loaded at server-startup.

You'll need to contact your host to resolve this. Refer them specifically to the discussion of LoadModule order versus module execution order in the Apache documentation. This is described specifically in the description of the AddModule directive [httpd.apache.org]; Modules are executed in the reverse order that they are loaded, and unfortunately, many hosts don't realize that and place script interpreter module load directives *after* mod_rewrite. If the script interpreter runs first, then no URL that runs a script can be rewritten.

This may not be the cause of your problem, but it is a likely suspect.

Jim