Snipchain
Snipchain

Reputation: 147

redirect url with question mark after url rewriting in htaccess

I'm looking for a pattern to do the right redirection after an url rewriting

test/14/optional-string-not-important?edit=ok

should redirect towards

test.php?id=14&edit=ok

...after url rewriting, I've made a rule like:

RewriteRule    ^test/([0-9]+)(/([a-z0-9,\.-]*))?(\?(.*))?$    test.php?id=$1&$5

but the question mark in (\?(.*)) doesn't want to escape I don't know why... any idea? Thanks in advance!

Upvotes: 2

Views: 922

Answers (1)

anubhava
anubhava

Reputation: 785058

You can't match QUERY_STRING in RewriteRule. Since you're just attempting to preserve existing query string you can just use QSA flag. QSA (Query String Append) flag preserves existing query parameters while adding a new one.

Try this rule instead:

RewriteRule ^test/([0-9]+)(/|$) test.php?id=$1 [L,NC,QSA]

Upvotes: 2

Related Questions