I have a site where I am using the CDN module in origin pull mode with Amazon CloudFront. Apache is configured so Drupal will handle www.example.com and static.example.com.

Is there a way to get Drupal to only use the static URL only for my static resources (images, CSS, JS, etc), and redirect other requests to www? Is the only real way to implement a hook_page_build() and check the Content-Type header to see if it begins with "text/html", and potentially redirect then?

1 Answer 1


If by static resources you mean resources for which the content is served from the server, using the content of a file, then hook_page_build() is not invoked for such resources.
It's the server that handles those requests, and Drupal doesn't do anything. In that case, you could edit the .htaccess file to redirect the users to the right domain.

That is what I would do also in the case it's Drupal to produce the content. Rather than letting Drupal produce the output, and redirect the user to the correct sub-domain, where the output would be produced again, I would rather redirect the user once it is clear what type of resource is being requested, and which is the URL of the resource.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.