我想用?s=
从/search/
重写为.htaccess
的网址字符串。
示例:http://hello.com/?s=hey
=> http://hello.com/search/hey
我该怎么做?
答案 0 :(得分:0)
可能是这样的
RewriteEngine On
RewriteRule ^search/(.*) index.php?s=$1 [QSA,L]
这样您就可以访问您的网站了
http://hello.com/search/hey
将被解释为http://hello.com/index.php?s=hey
希望这会有所帮助
答案 1 :(得分:0)
将此代码放在DOCUMENT_ROOT下的.htaccess中:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# external redirect from index.php?s=key to search/key
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?s=([^\s]+) [NC]
RewriteRule ^ search/%1? [L,R,NC]
# external redirect from search/key to index.php?s=key
RewriteRule ^search/(.+)$ index.php?s=$1 [L,NC,QSA]
答案 2 :(得分:0)
感谢答案的人,这对我有用,取自here。
RewriteCond %{QUERY_STRING} s=(.*)
RewriteRule ^$ /search/%1? [R,L]