0

In Drupal 7 I am using the Domain module to allow multiple subdomains of the format sub1.example.com, sub2.example.com, etc.

When I am sure that I can correctly identify the current subdomain, I will use a php test in the Block Visibility Settings to decide which menu to show to which subdomain.

To check I can use PHP to identify the current subdomain, I have set up a block with the code.

global $base_url;
$current_path = $base_url . '/' . current_path();
echo $base_url;
echo  "<br>";
echo $current_path;
echo  "<br>";

$actual_link = "$_SERVER[HTTP_HOST] $_SERVER[REQUEST_URI]";
echo $actual_link;

The result shows the subdomain from the first page that I access. When I switch page to another subdomain the new subdomain is not shown; the original one is still shown.

How can I can see the correct subdomain for the current page?

5
  • Sounds like Drupal is caching the result. To fix this, you'd have to add a cache context for subdomain to the cached item (likely the page cache). Explaining how to do so is more than I can explain here though, it would take some debugging and testing, and likely a few hours development.
    – Jaypan
    Mar 4, 2021 at 16:35
  • In fact I have changed the code I show in the original post, and I now end the code with a clearstatcache() statement. It has made no difference.
    – frank4360
    Mar 4, 2021 at 20:51
  • It's probably not that cache. Maybe the page cache.
    – Jaypan
    Mar 4, 2021 at 21:01
  • Neither db_query("DELETE FROM {cache_page};"); db_query("DELETE FROM {cache_path};"); work either
    – frank4360
    Mar 5, 2021 at 16:01
  • Might be cached in more than one place. But it's not something we can debug on a Q&A forum.
    – Jaypan
    Mar 5, 2021 at 16:04

0

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.

Browse other questions tagged or ask your own question.