Forum Moderators: phranque

Message Too Old, No Replies

Is it possible to dynamically redirect to the passed URL?

         

scott_h

8:01 pm on Apr 11, 2009 (gmt 0)

10+ Year Member



Hi. I am wondering if mod_rewrite (or any other module) can automatically capture a 'passed' url and dynamically redirect TO IT?

My purpose is to LOG the transaction, before sending the browser to an 'external' url.

Example Request:
[mysite.com...]

Desired Redirect:
[externalsite.com...]

IOW, I am wondering whether Apache can handle the whole dynamic transaction, without any external cgi (or other) program.

Thanks Much!

Scott

g1smd

8:31 pm on Apr 11, 2009 (gmt 0)

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



Yes it can.

Pull the URL from the parameter by looking at the QUERY_STRING.

Use a 301 redirect to the target URL, using the %1 backreference from there in the RewriteRule.

Be aware that this is an unsafe method as anyone who knows the format can use your site to bounce off.

You are *strongly* advised to validate the input URLs against a whitelist.

It's very easy to use a rewrite to a script that does a database lookup, and in that case you don't need to put the real URL as a parameter, but merely call by database record number.

scott_h

9:07 pm on Apr 11, 2009 (gmt 0)

10+ Year Member



OK. Thanks. I may have more questions, as I head down the rewrite path.

I am wondering, however, *why* would anyone want to 'bounce' off my site? I don't understand the benefit to them... oh (I'm getting a rhema)... I guess it would be to mask the referrer and ip, right? I see your point - not good.

In regards to the scripting... does Apache have any kind of native scripting engine of it's own, or, does it require an external scripting engine (e.g. Perl, PHH)? Probably a dumb question, but thought I would ask anyway. Currently, I do all of my *programming* within a database application which has webserver capabilities (whatever Apache cannot handle, it passes off to my custom application). However, I want to minimize the hits directly to my database application: (a) to conserve resources; b) to be able to continue serving as many requests as possible, even when my db app may be offline.

So, if I go the scripting route (which appears to be the best way), I would like to make it as *light* as possible on my server box. I'm guessing Apache cannot do database lookups on it's own, so is Perl the best solution?

Thanks again.

g1smd

9:15 pm on Apr 11, 2009 (gmt 0)

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



You never know what spammers might try next, so close the loophole before you get to find out the hard way.

I only use PHP and mySQL, so I'm not particularly qualified to say which language might be best here.

jdMorgan

3:43 am on Apr 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either PERL or PHP would be OK -- whatever you're most comfortable with.

Jim

scott_h

4:35 am on Apr 12, 2009 (gmt 0)

10+ Year Member



Thank you, gentlemen. I will be starting off 'new' with either PERL or PHP. Looks like an ideal opportunity to get my feet wet.