Forum Moderators: phranque
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]
Don't ever use this method:
RewriteRule ^/epp/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ ... 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