How to (.htaccess) rewrite the url of a specific search query?

£可爱£侵袭症+ 提交于 2019-12-11 06:19:19

问题


I wish to (.htaccess) rewrite the url of a search query when it has the "custom_title" parameter. Anyone can help me? I'd like to rewrite this url:

http://www.mysite.com/search.php?search_query=myquery&custom_title=mytitle

to this:

http://www.mysite.com/results/myquery/mytitle/


回答1:


Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^results/([^/]+)/([^/]+)/?$ /search.php?search_query=$1&custom_title=$2 [L,NC,QSA]



回答2:


You could use something like this:

RewriteRule ^/results/(.+)/(.+)/$ /search.php?search_query=$1&custom_title=$2

Then accessing URL http://www.mysite.com/results/myquery/mytitle/ in your browser will actually call your search.php file.



来源:https://stackoverflow.com/questions/18445785/how-to-htaccess-rewrite-the-url-of-a-specific-search-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!