如何使用.htaccess文件重定向

时间:2011-07-24 11:03:21

标签: .htaccess mod-rewrite redirect

我正在尝试这样做......

www.mysite.com/directory/*重定向到我的subdommain.mysite.com/directory/*

请帮帮我

RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^directory/(.*)$ http://subdommain.mysite.com/directory/$1 [R=301,L]

我想要它

1 个答案:

答案 0 :(得分:1)

如果您要将所有请求从www.mysite.com重定向到subdomain.mysite.com,请尝试将其添加到.htaccess文件中:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://subdomain.mysite.com/$1 [R=301,L]

如果您只想将/anydirectory/的请求从www.mysite.com/anydirectory/重定向到subdomain.mysite.com/anyotherdirectory/,请尝试将其添加到.htaccess文件中:

RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^anydirectory/(.*)$ http://subdommain.mysite.com/anyotherdirectory/$1 [R=301,L]