Answer the question
In order to leave comments, you need to log in
Why doesn't localization work in Laravel routing on Ubuntu 18.04 Apache?
After transferring the site from openserver to ubuntu, the site starts to give a 404 error on pages that have localization in the URL:
Route::group(
[
//LocalizationService::locale() - возвращает код языка из url
'prefix'=>LocalizationService::locale(),
'middleware'=> ['setLocale']
],
function ()
{
/** Главная страница*/
Route::get('/', '[email protected]', 'index');
/** Категории*/
Route::get('/{aliasCategory}', '[email protected]', 'category')->name('front.category');
/** Страница записи*/
Route::get('/{aliasCategory}/{aliasArticle}', '[email protected]', 'article')->name('front.category.article');
}
);
//site.ru/ru - вернёт ошибку 404
Route::group(
[
'prefix'=>'ru',
'middleware'=> ['setLocale']
],
function ()
{
/** Главная страница*/
Route::get('/', '[email protected]', 'index');
/** Категории*/
Route::get('/{aliasCategory}', '[email protected]', 'category')->name('front.category');
/** Страница записи*/
Route::get('/{aliasCategory}/{aliasArticle}', '[email protected]', 'article')->name('front.category.article');
}
);
//site.ru/ru - отобразит страницу
dd(LocalizationService::locale()); //Возвращает 'ru'
//site.ru/ru - отобразит 'ru'
Answer the question
In order to leave comments, you need to log in
I miraculously solved the problem, it was all about caching routes : when deploying, I took commands from here:
https://laravel.com/docs/5.8/deployment#autoloader... , the trick is that the command
php artisan route:cache
caches prefixes in routers and code
Route::group(
[
//LocalizationService::locale() - возвращает код языка из url
'prefix'=>LocalizationService::locale(),
'middleware'=> ['setLocale']
],
function ()
{
}
);
Route::group(
[
//LocalizationService::locale() - т.к. url нет, то вернёт и сохранит в кеш пустое значение
'prefix'=> '',
'middleware'=> ['setLocale']
],
function ()
{
}
);
php artisan route:clear
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question