用htaccess重写搜索页面查询URL [英] Rewrite search page query URL with htaccess
本文介绍了用htaccess重写搜索页面查询URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要提交搜索表单时,URL像这样:
I want when search form submitted, the URL be like this :
localhost/xampp/external/proj3/search/searchquery
代替此:
localhost/xampp/external/proj3/tools/search/search.php?query=searchquery
推荐答案
您可以在DOCUMENT_ROOT/.htaccess
文件中使用以下代码:
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /xampp/external/proj3
# external redirect from action URL to pretty one
RewriteCond %{THE_REQUEST} /search(?:\.php)?\?query=([^\s&]+) [NC]
RewriteRule ^ search/%1? [R=302,L,NE]
# internal forward from pretty URL to actual URL
RewriteRule ^search/([^/.]+)/?$ search.php?query=$1 [L,QSA,NC]
这篇关于用htaccess重写搜索页面查询URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文