Top Nav

Redirect With Query String

Let’s say you have URL like this:

that you want to redirect to a new url:

This is easily accomplished with a rewrite rule:

But what if the source URL has a url parameter like:

In this case we need to use  RewriteCond to match the url parameter:

Notice the question mark (?) at the end of “/new-url?”. This causes the query string to be discarded. If the question mark is not included then the redirect will go to:

If you want to keep the query string then you can explicitly add it with the QSA option like:

Also in Apache 2.4 and latter the QSD option can be used to exclude the query string with the same effect at the trailing question mark: