【问题标题】:htaccess redirect a specific extension to subdomainhtaccess 将特定扩展重定向到子域
【发布时间】:2012-11-07 04:28:33
【问题描述】:

我希望将特定文件夹中的特定扩展名 (mp3) 重定向/重写到使用 CDN 的子域。

为了让事情更清楚,我只希望在有人尝试像下载 mp3 之类的情况下将文件夹“compositions”中的 mp3 扩展名添加到子域中

http://www.example.com/compositions/interception.mp3

http://sub.example.com/interception.mp3 (subdomain on push zone CDN)

【问题讨论】:

    标签: apache .htaccess redirect url-rewriting cdn


    【解决方案1】:

    使用RewriteCond匹配主机名www.example.com,匹配时执行compositions/目录中的mp3重写。

    RewriteEngine On
    
    # If the domain matches www.example.com
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
    
    # Rewrite mp3's from composition/ to the CDN, capture filename in $1
    # Performs a 301 redirect
    RewriteRule ^compositions/(.*)\.mp3$ http://sub.example.com/$1.mp3 [L,R=301]
    

    【讨论】:

    • 不幸的是它不起作用! :(你能在最后尝试一下吗?
    • 我无法尝试,因为我不知道您的域是什么。
    • 我试过了,它一直在循环重定向到 /compositions,然后重定向到 composition/compositions,然后是 composition/compositions/compositions 等等..
    • @user1170540 你的 .htaccess 中有其他规则吗?
    • 是的。我目前正在尝试在没有任何其他规则的情况下使用文件夹中的 htaccess..
    猜你喜欢
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 2014-10-12
    • 2015-10-22
    • 2017-08-16
    相关资源
    最近更新 更多