2012-02-02 14 views
2

何が問題なのか把握するのに苦労しています。.htaccessでCDNのリダイレクトを使用すると画像にリダイレクトループが発生する

静的コンテンツをCDNにリダイレクトするために自分の.htaccessに自分のCDNのコードを追加すると、そのファイルにリダイレクトループが発生します。

私は彼らがファイルを読み込むのではなく、自分自身にリダイレクトしていることに気付きました。

私の.htaccessファイル:サイトを壊す

RewriteEngine On 

# Force no www 
RewriteCond %{HTTP_HOST} ^www [NC] 
RewriteRule ^.*$ http://domain.com/$0 [R=301,L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule ^index\.php$ http://domain.com/ [R=301,L] 

# Rewrite domain.com/p/contact to index.php?p=contact 
RewriteRule ^p/([^/]+)/?$ /index.php?p=$1 [L] 

私のCDNのコード:

<IfModule mod_expires.c> 
    ExpiresActive On 
    ExpiresDefault A0 

    # Set up caching for 1 week(s) 
    <FilesMatch "\.(jpe?g|gif|png|bmp|pdf|docx?|xlsx?|ppt|rar|zip|tar|gz|tgz|bz2|flv|avi|mov|wmv|mp3|wav)$"> 
     ExpiresDefault A604800 
     Header append Cache-Control "public" 
    </FilesMatch> 

    # Set up caching for 1 day(s) 
    <FilesMatch "\.(xml|txt)$"> 
     ExpiresDefault A86400 
     Header append Cache-Control "public" 
    </FilesMatch> 

    # Set up caching for 1 hour(s) 
    <FilesMatch "\.(js|css)$"> 
     ExpiresDefault A3600 
     Header append Cache-Control "proxy-revalidate" 
    </FilesMatch> 

    # Force no caching for dynamic files 
    <FilesMatch ".(php|cgi|pl|htm)$"> 
     ExpiresActive Off 
     Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform" 
     Header set Pragma "no-cache" 
    </FilesMatch> 
</IfModule> 

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{HTTP:Via} !\.s\.worldcdn\.com 
    # Flash wont work on cross-domain by default 
    RewriteCond $1   !^.swf$ [NC] 
    RewriteCond $1   "\.(jpe?g|gif|png|bmp|ico|js|css|pdf|docx?|xlsx?|ppt|rar|zip|tar|gz|tgz|bz2|flv|avi|mov|wmv|mp3|wav|xml|txt)$" [NC] 
    RewriteRule ^(.*)   http://cdn.domain.com/$1 [L,R] 
</IfModule> 

サブドメイン、CDNなどがすべて正しく設定されています。

多分CDNに問題がありますか? あなたの助けに感謝します!旗Lから

答えて

3

Apache Docs: flag_l

あなたはどちらか.htaccessファイルまたは<Directory>セクションでのRewriteRuleを使用している場合、ルールがどのように処理されるかをある程度理解することが重要です。これの簡略化された形式は、ルールが処理されると、書き換えられた要求がURL解析エンジンに渡され、URL解析エンジンがその内容を処理することです。書き直された要求が処理されると、.htaccessファイルまたはセクションが再び発生する可能性があり、したがって、ルールセットは最初から再実行される可能性があります。最も一般的には、ルールの1つが内部または外部のリダイレクトを引き起こし、要求プロセスをやり直す場合に発生します。


書き換え要求がエンジンを解析バックURLに渡され、以来、後に

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{HTTP:Via} !\.s\.worldcdn\.com 
    # Flash wont work on cross-domain by default 
    RewriteCond $1   !^.swf$ [NC] 
    RewriteCond $1   "\.(jpe?g|gif|png|bmp|ico|js|css|pdf|docx?|xlsx?|ppt|rar|zip|tar|gz|tgz|bz2|flv|avi|mov|wmv|mp3|wav|xml|txt)$" [NC] 
    RewriteRule ^(.*)   http://cdn.domain.com/$1 [L,R] 
</IfModule> 

いずれか
編集、ここで最後のRewriteRuleからこの行をリダイレクト:

RewriteRule ^(.*)   http://cdn.domain.com/$1 [L] 

か、あなたにも、ブラウザでのURIの変更をしたい場合

、最初RewriteCond

RewriteCond %{HTTP_HOST} !cdn\.domain\.com 
    RewriteCond %{HTTP:Via} !\.s\.worldcdn\.com 
    RewriteCond $1   !^.swf$ [NC] 
    RewriteCond $1   "\.(jpe?g|gif|png|bmp|ico|js|css|pdf|docx?|xlsx?|ppt|rar|zip|tar|gz|tgz|bz2|flv|avi|mov|wmv|mp3|wav|xml|txt)$" [NC] 
    RewriteRule ^(.*)   http://cdn.domain.com/$1 [L,R] 
+0

おかげで多くを追加! :) – rafleo

関連する問題