Jass Jass - 26 days ago 10
PHP Question

url rewrite when only parameter is on left and we need multiple on right

I have website in PHP and I am doing url rewrite using htaccess.

My current URL is

http://www.website.com/product.php?view=iYIDziy4kG


iYIDziy4kG = unique key


I want to make it like

http://www.website.com/product/category/sub-catgeory/product-name/iYIDziy4kG

I have made rule like this


RewriteRule products/(.*)/(.*)/(.*)/(.*) product.php?view=$1 [L]


and when I use

print_r($_REQUEST)


then it is picking unique key "iYIDziy4kG" in first (.*) but as per my requirements, it should be in last (.*)

what could be the possible solution in this case?

Answer Source

Either remove the parenthesis around the first three parameters or change $1 to $4.