hatxi
hatxi

Reputation: 75

PHP/Apache rewrite rules with multiple parameters?

I got the difficult when rewrite rules with multiple parameter,to modify a URL to SEO-friendly.

My URL:

http://domain/cat.php?alias=canon&sort=price&page=3

I want to have a rewrite rule so that the following:

http://domain/c/canon?sort=price&page=3

Heres my current rule:

RewriteEngine On
RewriteRule ^c/([a-z,0-9-]+)$ cat.php?alias=$1 [L]
RewriteRule ^c/([a-z,0-9-]+)?sort=([a-z]+)$ cat.php?alias=$1&sort=$2 [QSA]
RewriteRule ^c/([a-z,0-9-]+)?sort=([a-z]+)&page=([0-9]+)$ cat.php?alias=$1&sort=$2&page=$3 [QSA]

I try to get the params but it doesn't work. Anyone have any ideas on which rewrite rules to use?

Thank you! --hatxi

Upvotes: 1

Views: 193

Answers (1)

Capsule
Capsule

Reputation: 6159

RewriteRule ^c/([a-z,0-9-]+) cat.php?alias=$1 [L,QSA]

Should be enough. The QSA flag will take care of passing the sort and page parameters.

Your rules don't work because of the [L] flag on the first one, it just discards the rest because it always matches first.

Upvotes: 1

Related Questions