Question

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.

Était-ce utile?

La solution

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(GetResponseEvent $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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à drupal.stackexchange
scroll top