Santiago Santiago - 4 months ago 21
PHP Question

Categories and subcategories mod rewrite

i have this code as an example for a subcategory url,

the file is


The link to the url is like this:

<a href="store/subcategory.php?catid=guitars&subcatid=electrics"></a>

and the htaccess rule so far is

RewriteRule ^store/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ subcategory.php?catid=$1&subcatid=$2 [L]

As a result i want accomplish this,
Turn this url:


How can i do this? What am i missing?


You need an additional redirect rule:

RewriteEngine On

RewriteCond %{THE_REQUEST} /subcategory\.php\?catid=([^\s&]+)&subcatid=([^\s&]+) [NC]
RewriteRule ^ /store/%1/%2? [R=302,L,NE]

RewriteRule ^store/([\w-]+)/([\w-]+)/?$ subcategory.php?catid=$1&subcatid=$2 [L,QSA,NC]