HTAccess将搜索查询字符串重写为Pretty URL

时间:2018-02-01 16:25:26

标签: .htaccess mod-rewrite

我已经阅读了其他线程来配置下面的结果。我遇到的问题是该网址包含“本地”网站。服务器也是。

我的搜索网址为:

https://www.example.com/news/?s=recipe

(可以是"食谱","文章","新闻","地点"等)。

必需的输出结果:

https://www.example.com/news/search/recipe/

问题的一部分是新闻页面网址不会总是有搜索查询参数,因此必须将其纳入重写代码。

## Rewrite the Search s= to an SEO friendly output
<IfModule mod_rewrite.c>
#RewriteBase /
# external redirect from action URL to pretty one
RewriteCond %{THE_REQUEST} /news/\?s=([^\s&]+) [NC]
RewriteRule ^ news/search/%1? [R=302,L,NE]
#
# internal forward from pretty URL to actual URL
RewriteRule ^news/search/([^/.]+)/?$/ news/?s=$1 [L,QSA,NC]
</IfModule>

有更好的解决方案吗?

0 个答案:

没有答案
相关问题