0

How can I redirect visitors to a specific page based on the sub-domain? For example:

  • www.site.com goes to frontpage
  • checklist.site.com goes to checklist.site.com/checklist

My server is set to work with a wildcard (*.site.com). All sub-domains point to the same Drupal site.

I found Redirect based on query string about redirecting in Drupal 8, but I am not able to achieve what I want following what reported there.

1 Answer 1

0

The linked post points in the right directions, but contains a lot of code you don't need. Use this change record https://www.drupal.org/node/2013014 instead and check $request->getHost():

  public function checkForRedirection(RequestEvent $event) {
    if ($event->getRequest()->getHost() == '...') {
      $event->setResponse(new RedirectResponse('http://example.com/foo/'));
    }
  }

For a non-coding solution you can try Redirect Domain, a submodule of Redirect.

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.