Rayan
Rayan

Reputation: 23

duplicate variable in url rewrite with htaccess

I have a product page :

product.php

this page gets some GET requests .

1.product brand
2.product series of that brand

with click on brand , it will show that brand of the product :

product.php?brand=A

I've rewrite it with this command in htaccss :

RewriteRule ^product/([0-9a-zA-Z]+) product.php?brand=$1 [NC] 

and the url is :

product/A 

. so far so good. but here is my problem . I wanna show only one specific series of this brand , normally it works with this :

product.php?brand=A&series=a1 

. but when I use this line in htaccess :

RewriteRule ^product/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) product.php?brand=$1&series=$2 [NC] 

it doesn't work cause we encounter a duplication : brand=$1 used twice in 2 lines . I can't delete any of these 2 lines cause I need'em . so does anyone have a solution ?

Upvotes: 1

Views: 142

Answers (1)

Croises
Croises

Reputation: 18671

You can use:

RewriteRule ^product/([0-9A-Z]+)/?$ product.php?brand=$1 [NC,L] 
RewriteRule ^product/([0-9A-Z]+)/([0-9A-Z]+)/?$ product.php?brand=$1&series=$2 [NC,L] 

Upvotes: 1

Related Questions