用.htaccess重写一个奇怪的URL字符串

时间:2012-04-16 19:29:12

标签: wordpress .htaccess mod-rewrite

我想用?s=/search/重写为.htaccess的网址字符串。

示例:http://hello.com/?s=hey => http://hello.com/search/hey

我该怎么做?

3 个答案:

答案 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]