The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 06:37:58 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: mod_rewrite/PHP interaction: preserve originally requested URL  (Read 1957 times)
ratthing
Journeyman
***
Offline Offline

Posts: 75


View Profile
« on: December 06, 2007, 12:15:44 AM »

I am trying to keep the visitor's initial URL requested available they can be redirected there after they go through an age gateway.   Scripting for the gateway is PHP; the URL is getting rewritten to force them to the age gateway, so I'm getting that in my $_SERVER['REQUEST_URI'] rather than the original request.  Any suggestions on any other tactic that might work in PHP?  I didn't see anything obvious from the docs.

It looks to me like I'll need to use mod_rewrite to add a query string containing the originally requested URL to be able preserve it, or am I barking up the wrong tree?  I was hoping to avoid a lot of mod_rewrite fiddly bits, but I can't think of any other way to handle it.

Thanks for any pointers--
=RT=
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: December 06, 2007, 05:50:58 PM »

I think I understand what you're saying RT, let me know if not - I think you're asking how to keep the complete original URL when you reverse-proxy a request inbound towards another HTTP server. If this is correct, then you are as well - in Apache you'd mod_rewrite to the internal URL where the request needs to be handled, and append the original URL as a query param so that you can make use of it at the destination.

Here is and example of two things: a mod_rewrite that throws a proxied request to a renderer behind the public machine, as well as using a rewritemap to define *which machine* is the destination for load balancing. In this case, there is a small file called cluster_btd which defines which machines (defined by a hostname) are to be used as "online" for the virtual host. In the example below, all requests (I mean ALL requests) are handled by a single entity, the important part of this rewrite is the get params:

Code:
        RewriteMap              cluster  rnd:/www/resource/db/cluster_btd
        RewriteRule ^(.*)$ http://${cluster:online}$1?__site_id=SBTD1.0002&origip=%{REMOTE_ADDR}&port=%{SERVER_PORT} [P,L,QSA]

The cluster_btd file looks like this:
online     rcluster_01|rcluster_02|rcluster_03|rcluster_04|
stage      rcluster_05

so if someone requests a page, Apache will randomize rcluster_01 .. rcluster_04 and send the request backwards. If a call comes through for stage.thedomain.com then it is passed to a different machine. I have little text file editor scripts that allow me to define which machines are in production and which not, so if something is failing me I can take it out of the production site simply by changing the names in the text file.

Sory if this post makes no sense, I'm going fast between sessions at the PubCon... ping back if I completely confused you Wink
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
ratthing
Journeyman
***
Offline Offline

Posts: 75


View Profile
« Reply #2 on: December 07, 2007, 04:44:36 PM »

More investigation and your comment confirms my line of thought.  While in this instance, what I termed a "gateway" is actually just another script, I really should just think of it as a reverse proxy-like environment (since I've done that and have some clues about it  D'oh!).

Mod_rewrite twists my brain into knots for some reason.  Hopefully your example it will help me sort out where I am going with this.  Currently there is only one potential destination past the age check script, so I've gone 80/20 route for the mo.

Thanks again, Perk.
=RT=
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!