Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Perl script to handle requests to a http://.../path/*

by tachyon (Chancellor)
on Sep 12, 2003 at 06:23 UTC ( [id://290936]=note: print w/replies, xml ) Need Help??


in reply to Perl script to handle requests to a http://.../path/*

You need mod_rewrite. If you have a stock RH 7.x apache you will have it already. If the fragment presented chokes (because mod_rewrite is not installed) you will need to recompile apache. From memory if you just want mod_rewrite you have to pass these flags to configure:

./configure --enable-module=rewrite --enable-shared=rewrite

As always RTFM. Speaking of which if you want ssl, mod perl and mod_rewrite you will find a good description at http://perl.apache.org/docs/1.0/guide/install.html Note that you don't get the http://www.domain.com bit passed to mod_rewrite just /thedirectory/blah. We implement it like this using a VH container. We had some issues with it outside a VH container, even though the server is a dedicated one (no virtual hosts)

<VirtualHost *> ServerName your.domain.com RewriteEngine on RewriteLog /var/log/httpd/rewrite.log RewriteLogLevel 1 RewriteRule ^/thedirectory(.*)$ http://your.domain.com/cgi-bin/scrip +t.pl?$1 </VirtualHost>

In the rewrite rule we capture the bit after thedirectory in $1 to pass to our script. You can use a full http:// or a partial /cgi-bin rewrite path which will result in the user seeing or not seeing the redirect respectively (also from memory) We use the full path exteernal redirect for reasons that currently elude me ;-)

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Perl script to handle requests to a http://.../path/*
by xiper (Friar) on Sep 15, 2003 at 00:33 UTC
    I've been playing around with mod_rewrite and it seems to be able to achieve what i'm after. That is, if i could get it working properly... :)

    At the risk of being flamed for pushing this thread further off-topic, could someone help me out with this?

    What i actually want to achieve is to redirect all accesses, using mod_rewrite, to a perl script, so: http://www.domain.com/foo/bar gets sent transparently to: /cgi-bin/myscript.pl?foo/bar

    What i have at the moment is a .htaccess (no root, remember) that contains:

    RewriteRule ^(.*)$ /cgi-bin/myscript.pl?$1 [L]
    However, this gets caught in a loop, despite the [L], giving a 500 with:
    mod_rewrite: maximum number of internal redirects reached. Assuming co +nfiguration error. Use 'RewriteOptions MaxRedirects' to increase the +limit if neccessary.
    It was my understanding (from RTFMing!) that [L] is meant to avoid this?!? Where have i gone wrong?

    Update: found a solution, chain a neg regex in front

    RewriteRule !^/cgi-bin - [C] RewriteRule ^(.*)$ /cgi-bin/myscript.pl?$1 [L]

    - ><iper

    my JAPH: print"Just another Perl hacker\n"; # ^ look, no space! pretty tricky huh?

      Just apply a RewriteCond that says NOT /cgi-bin/blah first. Then the RewriteRule will only get invoked on the first pass, not once it has been done (untested)...

      There are also other hooks to prevent looping (they let you see it this request is a subrequest of the original) but that should do the trick.

      RewriteCond ! ^/cgi-bin/myscript.pl.*$ RewriteRule ^(.*)$ /cgi-bin/myscript.pl?$1

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        Thanks, although i managed to figure out a similar solution myself (although yours make more sense!).

        - ><iper

        my JAPH: print"Just another Perl hacker\n"; # ^ look, no space! pretty tricky huh?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://290936]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-28 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found