[thelist] Mod rewrite (Resolved)
Simon Perry
thelist at si-designs.co.uk
Mon Nov 8 03:49:39 CST 2004
David Kaufman wrote:
>Simon Perry <theist at si-designs.co.uk> wrote:
>
>
>>I'm having a problem getting mod rewrite to do quite what I want...
>>
>>RewriteCond %{QUERY_STRING} dest=([A-Z]{3})
>>RewriteRule ^(bin|cgi-bin)/flight-search.cgi /charter_flight.php?to=$2
>>[R=301]
>>
>>
>
>Um, first off, the $2 would reference the text matching the *second* set
>of parens in the rewriterule pattern, but you don't seem to *have* a
>second pair of parens in your rewriterule pattern.
>
>Second, if you change the $2 to $1 it will match, and append onto your
>new URL, either the "bin" or "cgi-bin" string, whichever matched in the
>old url. This doesn't appear to be what you were going for. To
>backreference the first parenthetic part from a rewrite condition
>pattern on an earlier line, try using %1 instead.
>
Dave,
The $2 was a left over from an earlier regex that I was trying before I
found out the the query string is actually sent separately to the URL. I
put %1 in and it now works! I also got rid of the first grouping as I
wasn't actually using it, so the final rule is as follows;
RewriteCond %{QUERY_STRING} dest=([A-Z]{3})
RewriteRule ^bin|cgi-bin/flight-search.cgi
http://www.charterflights.co.uk/charter_flight.php?to=%1 [R=301]
Thanks
Simon
More information about the thelist
mailing list