问题
/index.php?search_category=32
to
/32
How to do this by .htaccess in a way that when "/index.php?search_category=32" appear it auto change to "/32" with the same query string rules?.
Thanks in advance
回答1:
In the htaccess file in the directory your index.php file is in, you need to add these rules. For example, if the directory is /xyz/:
RewriteEngine On
RewriteBase /xyz/
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} ^search_category=([0-9]+)
RewriteRule ^index.php$ %1? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ index.php?search_category=$1 [L,QSA]
This is setup so you can swap the htaccess file in any directory as long as you change the RewriteBase to the directory the htaccess file is in (including the document root, /).
来源:https://stackoverflow.com/questions/12379561/htaccess-rule-apply-query-string-rule-and-change-the-url