htaccess的规则适用于查询字符串的规则,并更改网址 [英] htaccess rule apply query string rule and change the url
问题描述
/index.php?search_category=32
to
/32
如何通过 .htacces
做到这一点S在某种程度上,当/的index.php?search_category = 32
用相同的查询字符串规则显示它自动更改为/ 32
?
How to do this by .htacces
s in a way that when "/index.php?search_category=32"
appear it auto change to "/32"
with the same query string rules?.
在此先感谢
推荐答案
在htaccess文件中的目录的index.php文件是在,您需要添加这些规则。例如,如果该目录为 / XYZ /
:
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]
这是设置这样你就可以在任何目录中,只要在的RewriteBase
为你改变的htaccess文件所在的目录(包括文档根交换htaccess文件, /
)。
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, /
).
这篇关于htaccess的规则适用于查询字符串的规则,并更改网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!