Reputation: 63
My code:
RewriteCond %{REQUEST_URI} /category/.*/([^/]+)/? [NC]
RewriteCond %{REQUEST_URI} !category\.php [NC]
RewriteRule .*/category.php?cat=%1 [L,NC,QSA]
I want to get last word from URL as $_GET['cat']
, and it works, but when I put in URL only one or two slash then it doesn't work.
https://example.com/category - don't work
https://example.com/category/motorization - don't work
https://example.com/category/motorization/cars - work
https://example.com/category/motorization/cars/audi -work
Upvotes: 1
Views: 460
Reputation: 786329
You can use this rule to capture anything after /category/
in $1
:
Options -MultiViews
RewriteEngine On
RewriteRule ^/?category(?:/(?:.*/)?([^/]+))?/?$ category.php?cat=$1 [L,NC,QSA]
Upvotes: 1