重定向/索引到/ home

时间:2015-01-07 18:42:51

标签: .htaccess mod-rewrite redirect url-rewriting

我目前在.htaccess中有这个重写规则:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index/([^/]*)/?$ /index.php?user=$1 [L]
RewriteRule ^index/([^/]*)/([^/]*)$ /index.php?user=$1&sort=$2 [L]

我想将上述/index重定向到/home,其中还需要考虑参数。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

尝试将规则更改为:

RewriteRule ^index/(.*)$ /home/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^home/([^/]*)/?$ /index.php?user=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^home/([^/]*)/([^/]*)$ /index.php?user=$1&sort=$2 [L]