E.g. My site have two subdomains : domain_a and domain_b.

I create a path: "custom/a".

I hope:

domain_a can visit the path.

domain_b visit the path, get 404.

Except according to the golbal $domain in the code, does anyone have other solution?

1 Answer 1


There's a few ways to do that, but an easy one is to use the Panels module to define the page, coupled with domain_ctools

Then you can just add a selection rule or access control rule to specify the valid domains via the user interface.

Alternatively, you could do something with hook_menu access callbacks.

  • Thank for your fast reply. <br/> I just found a way use contex + [domaincontext](drupal.org/project/domaincontext. And I will also try your idea. Thanks!
    – Rylyn
    Jun 25, 2013 at 3:30
  • Worked for me! Thank for your idea. However, I still have a little problem with it. When the domain(not allowed visit) visit the page got "Access denied". I hope to show "Not found" or custom content. Do you have any good idea ?
    – Rylyn
    Jun 25, 2013 at 6:20
  • 1
    Add another "variant" to the page to match the other domain. You can also add an "http response code" variant for a 404 response. Jun 25, 2013 at 6:54

Your Answer

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

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