【问题标题】:htaccess redirect subdomain folder path to new URLhtaccess 将子域文件夹路径重定向到新 URL
【发布时间】:2014-07-25 17:32:12
【问题描述】:

我正在尝试重定向多个 URL ...

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

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

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

http://download.stevechab.com/album/arabb到http://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

谢谢!

史蒂夫

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

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

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

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

    【讨论】:

    • 嗯,我还有其他专辑要重定向……比如 download.stevechab.com/album/vanillarabb 到 arabbi.bandcamp.com/album/vanillarabb。
    • 好的,请检查更新的答案,但您应该在问题中明确说明。
    • 完成。对不起。那么,我可以添加文件夹路径吗?下载\.stevechab\.com/album/allergy$
    • 好的,您尝试过我建议的规则了吗?这应该适用于您声明的测试用例。
    • 还没有。我会这样做吗? RewriteCond %{http_host} ^download\.stevechab\.com$ [NC] RewriteRule ^(album/allergy.+)$ http://histamines.bandcamp.com/$1 [R=301,NC,L] RewriteRule ^(album/reallergy-remix-album.+)$ http://histamines.bandcamp.com/album/reallergy-remix-album/$1 [R=301,NC,L] RewriteRule ^(album/vanillarabb.+)$ http://arabbi.bandcamp.com/album/vanillarabb/$1 [R=301,NC,L] RewriteRule ^(album/arabb.+)$ http://arabbi.bandcamp.com/album/arabb/$1 [R=301,NC,L]
    猜你喜欢
    • 2012-09-17
    • 2013-11-08
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 2015-06-20
    • 2016-12-17
    • 1970-01-01
    • 2012-01-27
    相关资源
    最近更新 更多