I am using the Domain Access, Domain Access Views and Views modules.

I want to create a domain-specific view that will be displayed only in a specific subdomain of the website and if someone tries to access it from a different subdomain, he will be redirected to the proper domain.

So for example when a user navigates to:




he should be redirected to:


Is there a way to do that?

1 Answer 1


One solution would be to use hook_preprocess_html()

function MYTHEME_preprocess_html(&$variables) {
  global $_domain;
  if (arg(0) == 'myViewPath' && $_domain['subdomain'] != 'blog.example.com') {
    drupal_goto('http://blog.example.com/myViewPath', array(), 301);

Note that the global $_domain variable is provided by the Domain Access module.

Alternatively, in a custom module you could use hook_boot()

function MYMODULE_boot() {
  if (arg(0) == 'myViewPath' && $_SERVER['HTTP_HOST'] != 'blog.example.com') {
    exit(header('Location: http://blog.example.com/myViewPath', TRUE, 301));

Your Answer

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