我想重写一个URL字符串从?s=
到/search/
与.htaccess
。用.htaccess重写一个奇怪的URL字符串
例如:http://hello.com/?s=hey
=>http://hello.com/search/hey
我怎么能做到这一点?
我想重写一个URL字符串从?s=
到/search/
与.htaccess
。用.htaccess重写一个奇怪的URL字符串
例如:http://hello.com/?s=hey
=>http://hello.com/search/hey
我怎么能做到这一点?
感谢您的答案球员,这对我来说,取自here。
RewriteCond %{QUERY_STRING} s=(.*)
RewriteRule ^$ /search/%1? [R,L]
可能是这样的
RewriteEngine On
RewriteRule ^search/(.*) index.php?s=$1 [QSA,L]
这样,您将可以访问你的网站,如
http://hello.com/search/hey
将被解释为http://hello.com/index.php?s=hey
希望这有助于
将这个代码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]