htaccess将子域名文件夹路径重定向到新URL

时间:2014-07-25 17:32:12

标签: .htaccess redirect

我试图重定向一些网址......

http://download.stevechab.com/album/allergyhttp://histamines.bandcamp.com/album/allergy

http://download.stevechab.com/album/reallergy-remix-albumhttp://histamines.bandcamp.com/album/reallergy-remix-album

http://download.stevechab.com/album/vanillarabbhttp://arabbi.bandcamp.com/album/vanillarabb

http://download.stevechab.com/album/arabbhttp://arabbi.bandcamp.com/album/arabb

我试过这个:

RewriteEngine on
rewritecond %{http_host} ^download\.stevechab\.com/album/allergy [nc]
rewriterule ^(.*)$ http://histamines.bandcamp.com/album/allergy$1 [r=301,nc]

Redirect 301 http://download.stevechab.com/album/allergy http://histamines.bandcamp.com/album/allergy

它没有用。我可以访问stevechab.com htaccess文件,但不能访问download.stevechab.com htaccess文件。有没有办法做这个重定向?

这是我整个htaccess文件的样子......

ErrorDocument 404 http://www.stevechab.com

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^stevechab.com [nc]
rewriterule ^(.*)$ http://www.stevechab.com/$1 [r=301,nc]

Redirect 301 http://stevechab.com http://www.stevechab.com

rewritecond %{http_host} ^download\.stevechab\.com/album/allergy [nc]
rewriterule ^(.*)$ http://histamines.bandcamp.com/album/allergy$1 [r=301,nc]

Redirect 301 http://download.stevechab.com/album/allergy http://histamines.bandcamp.com/album/allergy

谢谢!

史蒂夫

1 个答案:

答案 0 :(得分:0)

您只能使用%{http_host}变量匹配主机/域名。

您可以在根.htaccess中使用此规则:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^download\.stevechab\.com$ [NC]
RewriteRule ^(album/.+)$ http://histamines.bandcamp.com/$1 [R=301,NC,L]