Recently I installed the CDN module. To avoid duplicate content I added a RewriteRule to my Apache config:
RewriteCond %{REQUEST_URI} !(^/(.*)(.js|.css|.jpg|.jpeg|.gif|.png)) [NC]
RewriteCond %{HTTP_ACCEPT} !(.*image.*|.*css.*|.*javascript.*) [NC]
RewriteCond %{HTTP_HOST} ^(static1.domain.com|static2.domain.com)$ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]
This is working, except when I'm using image styles. If the image exists everything works, but when it doesn't exist, I get a 301 to http://domain.com/index.php
These are the current situations using the implemented RewriteRule:
- GET static1.domain.com - 301 to http://domain.com - OK
- GET static1.domain.com/image.jpg - 200 - OK
- GET static1.domain.com/sites/domain/files/styles/.../image.jpg when file exists - 200 - OK
- GET static1.domain.com/sites/domain/files/styles/.../image.jpg when file doesn't exist - 301 to http://domain.com/index.php - WRONG
How do I force the image style file to be created when browsing to it from a static URL?