Reputation: 1189
I have some pages in my website which don't have user friendly URL. for eg.
www.mysite.com/index.php?route=product/category&path=68&vendorId=Cookie%20Dough
So I want to change it directly to www.mysite.com/Cookie-Dough
by using .htaccess.
so far I have hard coded following code in my .htaccess.
RewriteRule ^Cookie-Dough index.php?route=product/category&path=68&vendorId=Cookie%20Dough [NC,L]
which is working fine. But the problem is my vendor ids can change, so I want it dynamic. suppose if I have another URL like
www.mysite.com/index.php?route=product/category&path=68&vendorId=JELLY%20BEANZ
than I want it to be www.mysite.com/JELLY-BEANZ
without hardcoding the code in .htaccess.
any help would be appreciated.
Upvotes: 0
Views: 108
Reputation: 41219
You can use the following rule:
RewriteRule ^([^-]+)-([^/]+)/?$ index.php?route=product/category&path=68&vendorId=$1%20$2 [NC,L]
This will rewrite
/foo-bar
to
/ index.php?route=product/category&path=68&vendorId=foo%20bar
Upvotes: 0
Reputation: 1060
Replace /store
with your own subdirectory:
---.htaccess file start ----
Options +FollowSymlinks
RewriteEngine On
RewriteBase /store
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
# Added for non www queries
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www .%{HTTP_HOST}/store/$1 [R=301,L]
---.htaccess file ends ----
Upvotes: 1