问题
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