我有一个电子商务网站,可以通过多个域以多种语言提供该网站。例如:example.com(英语),example.fr(法语),依此类推...
我想要这样的动态URL:example.com/product/shoes-54
,example.com/produit/chaussures-54
。
如何根据域声明这些路由,知道/ produit仅在example.fr
和/product
仅在example.com
上可访问?
我已尝试根据域在交换机的情况下声明这些路由。
<?php
$domainName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
switch($domainName) {
case 'example.fr':
case 'www.example.fr':
$routes->connect('/ajoutez-votre-experience', ['controller' => 'Home', 'action' => 'add']);
$routes->connect('/contact', ['controller' => 'Home', 'action' => 'contact']);
$routes->connect('/conditions-d-annulation', ['controller' => 'Home', 'action' => 'refund']);
$routes->connect('/hote/:slug', ['controller' => 'Host', 'action' => 'index'])->setPass(['slug']);
$routes->connect('/experience/:slug', ['controller' => 'Experience', 'action' => 'index'])->setPass(['slug']);
$routes->connect('/region/:region', ['controller' => 'Location', 'action' => 'index'])->setPass(['region']);
$routes->connect('/region/:region/:region_sub', ['controller' => 'Location', 'action' => 'index'])->setPass(['region','region_sub']);
$routes->connect('/region/:region/:region_sub/:city', ['controller' => 'Location', 'action' => 'index'])->setPass(['region','region_sub','city']);
$routes->connect('/recherche', ['controller' => 'Search', 'action' => 'index']);
break;
case 'example.com':
case 'www.example.com':
case '':
default:
$routes->connect('/add-your-business', ['controller' => 'Home', 'action' => 'add']);
$routes->connect('/contact', ['controller' => 'Home', 'action' => 'contact']);
$routes->connect('/cancellation-condition', ['controller' => 'Home', 'action' => 'refund']);
$routes->connect('/host/:slug', ['controller' => 'Host', 'action' => 'index'])->setPass(['slug']);
$routes->connect('/experience/:slug', ['controller' => 'Experience', 'action' => 'index'])->setPass(['slug']);
$routes->connect('/location/:region', ['controller' => 'Location', 'action' => 'index'])->setPass(['region']);
$routes->connect('/location/:region/:region_sub', ['controller' => 'Location', 'action' => 'index'])->setPass(['region','region_sub']);
$routes->connect('/location/:region/:region_sub/:city', ['controller' => 'Location', 'action' => 'index'])->setPass(['region','region_sub','city']);
$routes->connect('/search', ['controller' => 'Search', 'action' => 'index']);
break;
}
一切正常,除非需要在CRON任务中获取产品的特定URL。由于我不在特定域中,因此无法“猜测” URL以及路由。
我曾考虑过命名路线,但我的意思是我需要声明所有主题才能在CRON任务中获取主题,这不适合我,因为我不希望在{{1} }。
在CakePHP应用程序中处理多个域/语言路由的最佳方法是什么?不幸的是,我找不到足够的文档。