Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dev_2108's avatar

Configure routes in Laravel so that they access the alias and not the main domain

Good afternoon. Please tell me, maybe someone has encountered this.

I have a website with the domain site-testing.com.

I have set up an alias for this site - site-testing.info.

There is a route -

Route::group(['prefix' => 'posts', 'as' => 'posts.site-testing.'], function () { Route::get('/{slug}', [PostController::class, 'show'])->name('show'); }); When I write a named route in a blade file

Read more then all links lead to the main domain, that is, to

http://site-testing.com/posts/slug

and not to an alias domain,

http://site-testing.info/posts/slug

Can you please tell me how to make the route point to an alias? (https://site-testing.info/posts/slug)

and not to the main domain (https://site-testing.com/posts/slug)

I can’t find a solution yet, the routes are always worked out in such a way that they lead to the main domain of the project, and not to an alias

0 likes
2 replies
tisuchi's avatar

@dev_2108 Two steps:

  1. Set domain based routing.

e.g.

Route::domain('site-testing.info')->group(function () {
    Route::group(['prefix' => 'posts', 'as' => 'posts.site-testing.'], function () {
        Route::get('/{slug}', [PostController::class, 'show'])->name('show');
    });
});
  1. Now use it in the blade.
<a href="{{ route('posts.site-testing.show', ['slug' => 'example-slug']) }}">Read more</a>

BTW, don't forget to clear

php artisan route:clear
php artisan config:cache
dev_2108's avatar

@tisuchi

Should I do the same for the main domain? should it be like this?



Route::domain('site-testing.info')->group(function () {
    Route::group(['prefix' => 'posts', 'as' => 'posts.site-testing.'], function () {
        Route::get('/{slug}', [PostController::class, 'show'])->name('show');
    });
});

Route::domain('site-testing.com')->group(function () {
    Route::group(['prefix' => 'posts', 'as' => 'posts.site-testing.'], function () {
        Route::get('/{slug}', [PostController::class, 'show'])->name('show');
    });
});

Please or to participate in this conversation.