2

I want to add a subdomain to my site (mysite.local) so it is, x.mysite.local and I want that to land on a custom page, i.e. a node, a view. I do not want to use the domain module because it has way more stuff that I need. Is there an easy way to do that in a custom module?

I tried doing something like this in settings.php but that does not seem to work:

// Get the subdomain:
$sub = explode('.',  $_SERVER['HTTP_HOST'])[0];
if ($sub == 'test') {
  $config['system.site']['page']['front'] = "node/12664";
}
0

I'm going to assume 1) you already have the proper DNS records set up and 2) you want a redirect (tells the browser to go to URL node/12664) and not a proxy rewrite (i.e. serve the page at node/12664).

Your best option would be to handle this in your .htaccess with mod_rewrite:

# Handle request for subdomain 
RewriteCond %{HTTP_HOST} ^test\.mysite\.local$ [NC]
RewriteRule (.*) https://mysite.local/node/12664 [L,R]

If you do want to try to handle this as a redirect in your settings.php you could try something like this:

if ($_SERVER["HTTP_HOST"] == 'test.mysite.local') {
    // Tell the browser to redirect to the HTTPS URL.
    header("Location: https://mysite.local/node/12664");
    exit;
}

If you want to serve a page from a different subdomain/host, without changing the URL, you'll have to delve into the hell of Apache ProxyPassReverse

  • Yes DNS is set up correctly. But I do not want to do any apache/.htaccess redirect. This should be possible to do by doing something similar to what the domain access module module does. But I have not been able to dig deep enough to figure out the peices of the code that does this. – awm Feb 2 at 18:39

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.