konghou
konghou

Reputation: 557

apache mod rewrite url with htaccess syntax

I wish to rewrite this url www.example.com/test1/aaa/bbb/?ccc=123 to www.example.com/test2?x=aaa&y=bbb&ccc=123

I used this rewrite rule RewriteRule test1/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?(.*) /test2?x=$1&y=$2&$3 [L]

but it failed to work for the last parameter. What should it be? Thanks.

Upvotes: 1

Views: 64

Answers (1)

anubhava
anubhava

Reputation: 784958

You don't match QUERY_STRING in RewriteRule. Use it this way using QSA flag:

RewriteRule test1/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?$ /test2?x=$1&y=$2 [L,QSA]
  • QSA (Query String Append) flag preserves existing query parameters while adding a new one.

Upvotes: 1

Related Questions