且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-24 09:20:48

您可以在 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]