重写规则的查询字符串URL静态化重写、字符串、静态、规则

2023-09-02 09:54:01 作者:星可摘你不不可得

我有一个基于标签的搜索按钮链接到mydomain.com/product/search/?tag=hoodies,我想在浏览器重写显示为mydomain.com/hoodies/(但仍拉从内容原始URL)。

I have a tag based search button linking to mydomain.com/product/search/?tag=hoodies that I want to rewrite in the browser to display as "mydomain.com/hoodies/ (but still pull the content from that original URL).

它是一个纯粹的美学动,我曾尝试:

Its a purely aesthetics move, I have tried:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^tag=tanks
RewriteRule ^product/search/$ /tanks/ [L,QSA,NC]

犯规对我的工作,有什么建​​议?

Doesnt work for me, any suggestions?

推荐答案

您可以在 DOCUMENT_ROOT /的.htaccess 文件中使用此code:

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} s/+product/search/?tag=([^s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ product/search/?tag=$1 [L,QSA]