3

A site responds to internal.example.com, and external.example.com.

Content editors all use internal. When Drupal generates the cached output, all images are now absolute URLs pointing to an internal domain, making them fail.

How would you handle this?

3 Answers 3

1

I use the sledgehammer approach and search/replace from template_process_html:

function foo_process_html (&$variables)
{
  $variables["page"] = str_replace("http://internal.example.com/", "/", $variables["page"]);
}

You can also get fancy and use preg_replace if you need better control. I typically end up needing this when I move a site from our staging server, which is a subdomain off of ours, onto a client's own domain.

If I were in your shoes, I would think about having an internal theme and an external theme, combined with one of the choose-a-theme-based-on-domain-name solutions. Then you can add preprocess/process as needed to just the external theme.

1

I think that your best option is to create a filter to replace the URL on the fly. While you could replace it with the URL of the external domain, it would be better to replace it with a relative URI instead. There's a dead module that does this which you could adapt or take over for your needs.

The related module list is also worth exploring for other ... novel solutions.

Edit: Further information from the OP suggests that Pathlogic might also be a good fit especially when considering the provided use cases.

4
  • I'm not sure I understand how that would work. Input filters and images?
    – Letharion
    Jul 8, 2012 at 12:33
  • I'm assuming that your content editors are using absolute URLs in their markup in textareas. I can't think of any other situation where absolute URLs are used instead of relative ones. Or I've misunderstood your question altogether.
    – user7667
    Jul 8, 2012 at 21:05
  • Images from an image-style get output with absolute urls. Yours do not?
    – Letharion
    Jul 9, 2012 at 6:44
  • I believe that they do in D7. But in any event, if they are inside an element which supports filters, you should be able to use another filter to replace the URLs accordingly. For this specific case, perhaps you can consider drupal.org/project/pathologic : see the use cases here: drupal.org/node/257026#example-use-cases
    – user7667
    Jul 9, 2012 at 11:07
0

One solution could be to manipulate the URL's with hook_file_url_alter, and another option, not file specific, could be hook_url_outbound_alter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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