[thelist] Mod rewrite

David Kaufman david at gigawatt.com
Sun Nov 7 17:33:09 CST 2004


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.

> Any pointers or links to decent tutorials would be much appreciated.

Well, there's just the Apache docs themselves, for the mod_rewrite
module:
http://httpd.apache.org/docs/mod/mod_rewrite

and (linked from the bottom of that) the "URL Rewriting Guide":
http://httpd.apache.org/docs/misc/rewriteguide.html

which is a *bit* more tutorial-like, but reported by many to still
require a voodoo doctorate to understand it.

hth,

-dave



More information about the thelist mailing list