现在我有以下网址 http://example.com/products/?category=clothes 我的主逻辑依赖于从url接收的get参数。 我有什么方法可以改变结构 http://example.com/products/clothes,还有带衣服的类别参数吗? 我尝试使用htaccess - 我试过这个,但它没有用。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^products/([^/]+)$ products/$1/?category=$1 [L]
答案 0 :(得分:0)
您可以使用.htaccess
:
RewriteEngine On
RewriteCond %{QUERY_STRING} category=(.+) [NC]
RewriteRule ^(.*)$ http://example.com/products/%1? [R=301,NC,L]
这会留下您的网址:http://example.com/products/clothes
我们在这里做的是抓取变量category=
,并使用%1
抓取与之关联的任何内容并将其放在网址的末尾。
然后,我们使用?
停止原始查询,例如,?category=clothes
显示在网址的末尾。
确保在>>测试之前清除缓存。