重写规则的查询字符串URL静态化 [英] RewriteRule for query string to static URL

查看:166
本文介绍了重写规则的查询字符串URL静态化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于标签的搜索按钮链接到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]

这篇关于重写规则的查询字符串URL静态化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆