htaccess rule apply query string rule and change the url

半腔热情 提交于 2020-02-07 19:33:14

问题


 /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

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