Rewrite condition is not working

2019-04-16 00:23发布

问题:

How to rewrite the URL for my search page in opencart that is like

http://IP/opencart/index.php?route=product/search&filter_name=24

But I need to display it like

http://localhost/opencart/product/search/42

orelse in any formate that is an userfreindly.I have tried like

RewriteEngine On
RewriteBase /opencart
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

RewriteBase /opencart 
RewriteRule ^search$ index.php?route=product/search  [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/search$
RewriteRule ^([^?]*) index.php?route=$1 [L,QSA]

回答1:

How about this:

RewriteBase /
RewriteRule ^opencart/([^/]*)/([^/]*)/([^/]*)$ /opencart/index.php?route=$1/$2&filter_name=$3 [L]

Please note that the slash in the route parameter complicates things.