Experience in mod_rewrite in Apache 2.2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everyone,

Recently I begin learn capabilities of mod_rewrite, and found that task, which I want to resolv, did not resolvs with help of mod_rewrite (or I wrongly thinking, and I want to consult).

So, I have Router host, which stand on border between my local network an Internet. Also, at my local network where are two resources by the point of view of Router host:

http://internal_network_host/first.html
http://internal_network_host/third.html

Well, I want to reproduce next two scripts:

1) If Router gets request from Internet like
   http://router.com/first
he should proxy that request to access http://internal_network_host/first.html resource. So, it's look like the user from Internet accessed http://internal_network_host/first.html directly.

2) If Router gets request from Internet like,
   http://router.com/second
he sould redirect client (responce 302) to http://router.com/third, where client could access via proxy mechanism (like first case) resource http://internal_network_host/third.html. So:

client: http://router.com/second
router: 302 http://router.com/third
client: http://router.com/third
and router return content of http://internal_network_host/third.html resource.


To reproduce such schema via standart RewriteRule sets - it's, I think, easy.
But I want do it using external program, like this:

RewriteEngine on
RewriteLog      "/var/www/html/rewrite.log"
RewriteLogLevel 255
RewriteLock     /var/www/html/redir.lock
RewriteMap      rd      prg:/var/www/html/redirect.pl
RewriteRule     ^(.+)$ ${rd:%{THE_REQUEST}}


and source code of external program, like this:

-----------------------8<---------------------------------------------
#!/usr/bin/perl
$| = 1;
while (<STDIN>) {
       $request = $_;
       if ($request eq "GET http://router.com/first HTTP/1.1" ) {
proxy to access to resource http://internal_network_host/first.html
       } elsif ($request eq "GET http://router.com/second HTTP/1.1" ) {
               redirecting to http://router.com/third
       } else {
               do something else....
       }
}
-----------------------8<---------------------------------------------

And now, I did not understand how, by using only one
RewriteRule     ^(.+)$ ${rd:%{THE_REQUEST}}
rule and one programs, I can achieve such goal.

I tell, why I need only this one rule, which grabs all requests and calls one external program for every request: because I will apply such scheme to virtual domains like:
[0-9a-z]*.router.com
and I some domains I will just proxing, and another domains I will redirect to another resource. All this should be done by external program, and that why I want to aks a help.

Thanks for helping me.
Dmitriy.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux