Redirecting to a page based on the sub-domain
-
06-02-2021 - |
题
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.
解决方案
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.
不隶属于 drupal.stackexchange