I am having a hard time figuring out what is wrong.
As soon as I add my CDN’s code to my .htaccess to redirect static content to the CDN, it results in a redirect loop on those files.
I noticed they keep redirecting to themselves instead of loading the file.
My .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]
My CDN’s code that breaks the site:
<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>
Subdomains, CDN etc. are all set up correctly.
Maybe it’s a problem with the CDN?
Cheers for your help!
From Flag
L: Apache Docs: flag_l :Since, rewritten request is handed back to the URL parsing engine, after redirect from the last
RewriteRulehere,either
edit this line to :
or,
if you want to have the URI change at the browser as well, add the first
RewriteCond