0

I have Multi-site setup , want to make available custom page say '/speakers' on domain1 site but not on domain2 site

I have tried to figured out in routing.yml file to check is there way to pass any variable in route where I can define that route should available for specific domain only, even I tried with the alter routes approach as well but no luck.

Note: Both sites has same custom module installed.

5
  • Does this mean each site has the same custom module installed that provides the route? If so the question is missing that information. Commented Oct 12, 2023 at 11:16
  • Yes , both sites has same custom module installed, updated that missing info. Commented Oct 12, 2023 at 11:41
  • One solution is not to install the module on some sites. Another is to define the route dynamically in PHP. Commented Oct 12, 2023 at 11:56
  • Yet another is to have the route controller return a 404 base on the request domain. Commented Oct 12, 2023 at 12:00
  • Thanks a lot, I used kind of similar approach in which removed the route conditionally by using alter routes() Commented Oct 20, 2023 at 15:45

1 Answer 1

0

Just for record purpose, posting answer:

I used alter routes() approach in which used remove function w.r.t to domain condition:

 $collection->remove('route_name'); 

Created: module_name.services.yml (root of custom module)

module_name.route_subscriber: class: Drupal\module_name\Routing\RouteSubscriber tags: - { name: event_subscriber } 

Created: RouteSubscriber.php (module_name\src\Routing)

<?php namespace Drupal\module_name\Routing; use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Component\Routing\RouteCollection; class RouteSubscriber extends RouteSubscriberBase { protected function alterRoutes(RouteCollection $collection) { $domain = \Drupal::request()->getHost(); // check domain if($domain == 'domain_name'){ if ($collection->get('route_name')) { // remove route conditionally $collection->remove('route_name'); } } } } 

Info: I Choose this particular approach becoz I need to enabled same module for both sites

To get more info related to routes, visit to this documentation link on official site of DRUPAL

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.