Host-Name Routing in CakePHP

Is it possible to use domain specific routes in cakephp?

for example, let's say I have 2 domains: manufacturer.comandproductname.com

productname.comparked on manufacturer.com.

I would like to create a route like this:

Router::connect('http://www.productname.com/', array('controller' => 'products', 'action' => 'view', 'productSlug'));

so basically the index for the .com manufacturer is the default pages/index, but for productname.comit should beproducts/view/productSlug

Is this possible with Cake?

+3
source share
2 answers

I will simply answer my question with the solution I came up with.

Instead of checking the domain inside the routes, the best way would be to check the host name before determining the routes. For instance:

if($_SERVER['HTTP_HOST']=='productname.com')
   Router::connect('/', array('controller' => 'products', 'action' => 'view', 'productSlug'));
else
   Router::connect('/', array('controller' => 'pages', 'action' => 'index'));

? ? , :)

+4

, , , . , , ;).

, , , (, AppController). .

+1

Source: https://habr.com/ru/post/1754771/


All Articles