I have been testing sub-domain routing functionality in Laravel 5 and have had success with the following code as described in the docs. When the user visits {username}.mysite.com, the user profile view is shown as expected.
Route::group(['domain' => '{username}.{tld}'], function () {
Route::get('user/{id}', function ($username, $id) {
//
});
});
But, I was expecting a bit of different behavior from what I am experiencing. When the user visits the site through the sub-domain, all of the links in my views now retain the sub-domain within them. All of the other links like {username}.mysite.com/home
and {username}.mysite.com/login
etc... are fully functional, but I don't understand why Laravel is populating all of my links with the sub-domain and/or how I can get rid of this and only retain the sub-domain for just the single route. I want all of the other links in my views to be like mysite.com/home
and mysite.com/login
. I was hoping to just use {username}.mysite.com
as a quick access point for site visitors, not to retain it in all views.
What can I do to change this behavior?
Move routes you don’t want prefixing with the subdomain outside of the route group: