Jak automaticky přesměrovávat na URL s lang parametrem?

crassus
Backer | 76
+
0
-

Ahoj, rád bych docílil automatického přesměrování na URL s parametrem lang:

  • z domena.cz/customerId/ na domena.cz/customerId/cs
  • z domena.cz/customerId/popup na domena.cz/customerId/cs/popup

Prosím o radu, jestli někdo víte jak na to. Částečně tak funguje i nette.org.

Musím k tomu použít .htaccess nebo se to dá udělat v RouterFactory.php?

Takto vypadá router:

$router[] = new Route(CUSTOMER_ID . '/<lang>/<slug>-<id \d+>', [
    'presenter' => 'Front',
    'action' => 'default',
    'lang' => [
        Route::FILTER_TABLE => [
            'cs' => 'cs',
            'en' => 'en'
        ],
        Route::FILTER_STRICT => true
    ],
    'id' => [
        Route::FILTER_IN => function ($id) use ($product) {
            $p = $product->getProductById($id, 'cs', 'CZK');
            return $p ? $id : null;
        },
    ]
]);

$router[] = new Route(CUSTOMER_ID . '/<lang>/<popup>', [
    'presenter' => 'Front',
    'action' => 'default',
    'lang' => [
        Route::FILTER_TABLE => [
            'cs' => 'cs',
            'en' => 'en'
        ],
        Route::FILTER_STRICT => true
    ],
    'popup' => [
        Route::FILTER_TABLE => [
            'billing-information' => 'billing-information',
            'chat' => 'chat'
        ],
        Route::FILTER_STRICT => true
    ]
]);

$router[] = new Route(CUSTOMER_ID . '/<lang>/', [
    'presenter' => 'Front',
    'action' => 'default',
    'lang' => [
        Route::FILTER_TABLE => [
            'cs' => 'cs',
            'en' => 'en'
        ],
        Route::FILTER_STRICT => true
    ]
]);

Díky!

Editoval crassus (19. 9. 2018 13:05)

crassus
Backer | 76
+
0
-

Pochopil jsem, že když mi nikdo neodpovídá, tak to asi bude v dokumentaci. A taky že jo! Škoda že je to tam tak nenápadné až schované.

Stačilo přidat: [!<lang=cs>] a bylo hotovo :)