I want to go from:




I tried the following and it doesn't seem to catch:

 RewriteRule "^directory\/results\?category=10&dir=asc" "\/staticfile\.html" [R, L]

I can get it to redirect using:

 RewriteCond %{REQUEST_URI} "^directory\/results" [NC]
 RewriteCond %{QUERY_STRING] category=10&dir=asc
 RewriteRule (.*) "\/staticfile\.html"

But then it appends the parameters after html in the last example.

  • Interestingly, this question is not actually answered in the canonical question/answer
    – Colt
    May 6, 2016 at 14:06

1 Answer 1

  RewriteRule (.*) /staticfile.html?

Per the Apache RewriteRule documentation,

By default, the query string is passed through unchanged. * * * * * When you want to erase an existing query string, end the substitution string with just a question mark.

  • Yep found out that Apache 2.2 does not make use of the QSD flag. In Apache 2.4 this flag is available to shut off the default Apache rewrite behavior of automatically appending query parameters from the old to the new URL. My configuration looks like this and it works: RewriteCond %{QUERY_STRING} category=10&dir=asc&order=name&format=165 RewriteRule (.*) "\/4k-ultra-hd\.html?" [R,L]
    – brenguy
    May 8, 2016 at 16:17
  • QSD is a little different - it is when you want to add a get rid of an existing query string in favor of a replacement. You just need the ? with nothing following for your setup.
    – Colt
    May 8, 2016 at 16:20
  • @brenguy - BTW, why are you trying to use regular expression syntax in the Substition string? The RewriteRule substition string is plain text, exept for inclusion of back-references, server-variables, and mapping-function calls, all of which have a speficied(not regular expression) syntax
    – Colt
    May 8, 2016 at 16:57
  • If i am understanding the question correctly... are you asking me why I am specifying rewriteconditions or why am I using (.*)?
    – brenguy
    May 9, 2016 at 18:31
  • @brenguy - I am asking about the formating you use for the substitution string (the "\/4k-ultra-hd\.html?" part). It looks like you are writing this as if it was regular expression, which it is not. See the Apache RewriteRule documentation for what may be included in the substitution string. It should probably be just /4k-ultra-hd.html? (i.e., no escape, quotes) as suggested in my answer.
    – Colt
    May 9, 2016 at 19:26

Not the answer you're looking for? Browse other questions tagged .