Forum Moderators: phranque
[testsite.com...]
I did a RewriteMatch to change it to this:
[testsite.com...]
Easy as pie, right? So here's my RedirectMatch:
RedirectMatch 301 /deals/([a-zA-Z0-9¦\-]+)_([0-9]+)\.html [testsite.com...]
It works (kind of), but I end up with this:
[testsite.com...]
Obviously, I don't want all that query string data at the end. What am I doing wrong? Thanks!
So what's happening is this:
You request the static URL.
The mod_rewrite code rewrites that URL into the query-string-form needed to call your script.
Now your RedirectMatch code runs, modifies only the URL (and not the appended query string), and invokes an external redirect.
This causes the query-stringed URL to appear in your browser address bar as your browser now asks for it in response to the redirect response from the server.
Possible solution (assuming you can put all the code into the same .htaccess file): Use mod_rewrite directives instead of mod_alias directives like RedirectMatch. Put your new redirect ahead of the rules that internally rewrite the script requests.
By having all the code in the same file, and by using the same module to do both functions, you can enforce a desired execution order; Otherwise, this can be difficult or even impossible to do.
In case it's not clear, each Apache module reads your access file in turn. The order in which they do this is set by the server configuration. As each module processes your .htaccess file, it executes only the directives that it understands, and ignores everything else. Therefore, the code is not executed in the order that you wrote it; Only the directives for any one given module are executed in the order in which they appear in the file. So, maybe mod_rewrite executes first, followed by mod_alias, which is your current case. But it could be the other way around -- it is mod_alias first, mod_rewrite second on the server I was working on today.
Best practice: Don't mix modules except when absolutely necessary.
Jim