Forum Moderators: phranque

Message Too Old, No Replies

Mod-rewrite problem with using many variables

mod-rewrite, multiple variables

         

pride7

11:01 am on Jul 14, 2009 (gmt 0)

10+ Year Member



Mod-rewrite problem with using many variables

Hello,

I have this really ugly URL that I need to rewrite into something shorter and easier but so far without much luck. I have tried several different approaches. Any advice?

Original URL:
/deeplink/entryPointParameterised.do?language=dk&Search/OriginDestinationInformation/Origin/location=CITY_CPH_DK&Search/OriginDestinationInformation/Origin/location_input=Kobenhavn&Search/OriginDestinationInformation/Destination/location=CITY_AMS_NL&Search/OriginDestinationInformation/Destination/location_input=Amsterdam&Search/Passengers/adults=1&Search/Passengers/children=0&Search/Passengers/infants=0&Search/searchType=F&Search/DateInformation/departDate=21/10/2009&Search/DateInformation/departDay=21&Search/DateInformation/departMonth=10&Search/DateInformation/departYear=2009&Search/DateInformation/returnDay=23&Search/DateInformation/returnMonth=10&Search/DateInformation/returnYear=2009&Search/DateInformation/returnDate=23/10/2009&Search/flightType=return&Search/Protocol=http

URL I want:
/epp/dk/CITY_CPH_DK/Kobenhavn/CITY_AMS_NL/Amsterdam/1/1/1/F/21/10/2009/21/10/2009/23/10/2009/23/10/2009/return/http

Approach 1. (Went halfway through, looked like it stopped at dates around variable #10):
RewriteRule ^/epp/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([0-9]+)/([0-9]+)/([0-9]+)/([^/.]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([^/.]+)/([^/.]+)$ [localhost:6124...] [P,L]

Approach 2. (Totally unsuccesful)
RewriteRule ^/epp/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)$ /deeplink/entryPointParameterised.do?language=$1&Search/OriginDestinationInformation/Origin/location=$2&Search/OriginDestinationInformation/Origin/location_input=$3&Search/OriginDestinationInformation/Destination/location=$4&Search/OriginDestinationInformation/Destination/location_input=$5&Search/Passengers/adults=$6&Search/Passengers/children=$7&Search/Passengers/infants=$8&Search/searchType=$9&Search/DateInformation/departDate=$10/$11/$12&Search/DateInformation/departDay=$13&Search/DateInformation/departMonth=$14&Search/DateInformation/departYear=$15&Search/DateInformation/returnDay=$16&Search/DateInformation/returnMonth=$17&Search/DateInformation/returnYear=$18&Search/DateInformation/returnDate=$19/$20/$21&Search/flightType=$22&Search/Protocol=$23 [P,L]

Approach 3. (Totally unsuccesful)
RewriteRule ^/epp/([A-Za-z]+)/([A-Za-z_]+)/([A-Za-z]+)/([A-Za-z_]+)/([A-Za-z]+)/([0-9]+)/([0-9]+)/([0-9]+)/([A-Za-z])/
([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([A-Za-z]+)/([A-Za-z]+)$ /deeplink/entryPointParameterised.do?language=$1&Search/OriginDestinationInformation/Origin/location=$2&Search/OriginDestinationInformation/Origin/location_input=$3&Search/OriginDestinationInformation/Destination/location=$4&Search/OriginDestinationInformation/Destination/location_input=$5&Search/Passengers/adults=$6&Search/Passengers/children=$7&Search/Passengers/infants=$8&Search/searchType=$9&Search/DateInformation/departDate=$10/$11/$12&Search/DateInformation/departDay=$13&Search/DateInformation/departMonth=$14&Search/DateInformation/departYear=$15&Search/DateInformation/returnDay=$16&Search/DateInformation/returnMonth=$17&Search/DateInformation/returnYear=$18&Search/DateInformation/returnDate=$19/$20/$21&Search/flightType=$22&Search/Protocol=$23 [P,L]

Approach 4. (Totally unsuccesful)
RewriteRule ^/epp/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ /deeplink/entryPointParameterised.do?language=$1&Search/OriginDestinationInformation/Origin/location=$2&Search/OriginDestinationInformation/Origin/location_input=$3&Search/OriginDestinationInformation/Destination/location=$4&Search/OriginDestinationInformation/Destination/location_input=$5&Search/Passengers/adults=$6&Search/Passengers/children=$7&Search/Passengers/infants=$8&Search/searchType=$9&Search/DateInformation/departDate=$10/$11/$12&Search/DateInformation/departDay=$13&Search/DateInformation/departMonth=$14&Search/DateInformation/departYear=$15&Search/DateInformation/returnDay=$16&Search/DateInformation/returnMonth=$17&Search/DateInformation/returnYear=$18&Search/DateInformation/returnDate=$19/$20/$21&Search/flightType=$22&Search/Protocol=$23 [P,L]

jdMorgan

5:49 pm on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mod_rewrite has a limit of nine RewriteRule back-reference variables, $1 through $9, and nine RewriteCond back-reference variables, %1 through %9. You *can* define your own additional variables, but that seems like too much work here.

Don't ever use this method:

 RewriteRule ^/epp/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ ... 

-- the use of multiple ".*" patterns is hugely inefficient, and using this rule (if it worked) would likely bring your server to its knees. This rule would require thousands of back-off-and-retry matching attempts to process... I shudder to think of the performance impact of using it. The other patterns you posted above with negative-match subpatterns will be processed in single left-to-right passes, and are much, much, much more efficient.

This problem looks to be far beyond what mod_rewrite can do well. I would suggest rewriting all of these requested URL-paths to a script --either your existing script or a new one purpose-built-- to do the translation. I think you will find that getting the job done will be much easier with the facilities of a full-on scripting language.

Basically, just rewrite *any* requested URL-path starting with "epp/" to the script, and pass the rest of the URL-path as a single query parameter (or use AcceptPathInfo if you're hosted on Apache 2.x). The script can then validate the requested URL-path and translate it, reject it, or redirect it as you wish.

Jim

pride7

7:28 am on Jul 15, 2009 (gmt 0)

10+ Year Member



Hi Jim,

Thanks a lot for your help. I guess I have to approach this whole thing in a different way like you suggests.

Thx,
Hans