laravel 5 subdomain redirected to homepage

2019-09-13 02:17发布

I have a site that can be access in stage.mysite.com and it has a subdomain profile.stage.mysite.com but it displays the content of stage.mysite.com when I try to access it.

in my server I have configured the hosting.

ServerAdmin webmaster@localhost
ServerName stage.mysite.com
ServerAlias *.stage.mysite.com
DocumentRoot /var/www/staging.mysite.com/public

in my routes.php this is the code.

Route::group(['domain' => 'profile.stage.mysite.com'], function()
{
    Route::get('/', 'FrontendController@profile');
});

this I expect to be called. any ideas?

This is my entire routes.php

Route::get('testemail', function() {
    return view('emails.new-group');
});
Route::get('decode', function(){
    var_dump(json_decode('[{"key":"wifi","info":"dasdasd"}]'));
});
require 'routes_backend.php';

Route::controller('/app', 'UserController');

// homepage
Route::get('/', function () {
    return view('homepage');
});

Route::group(['prefix' => 'test'], function() {
    Route::group(['prefix' => '{company}'], function($company){
        Route::get('tester', function($company){
            return $company;
        });
    });
});
// subdomain 
Route::group(['domain' => 'profile.stage.mysite.com'], function()
{
    Route::get('/', 'FrontendController@dummyresort');
});

1条回答
Root(大扎)
2楼-- · 2019-09-13 02:58

For future references, here is the answer and the concept:

Before trying to analyze the problem at the application level, make sure that you can ping your server using the subdomain.

After that is settled, the catch here is the same principle as firewalls and NAT: The more restrictive comes first. In this case, the subdomain would show the same information as the main domain because in the routes.php file the homepage / is declared first.

 // homepage 
 Route::get('/', function () {
    return view('homepage'); 
 });

When you navigate to the sub-domain, he matches this route and then it gets served and the request is finished. Since this is a much broader (without any limitation whatsoever) route, it should be the last thing to be declared, so when a subdomain route comes in, it finds first it's own restricted routes and matches to serve.

查看更多
登录 后发表回答