laravel 5子域重定向到主页 [英] laravel 5 subdomain redirected to homepage

查看:83
本文介绍了laravel 5子域重定向到主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在stage.mysite.com中访问的站点,并且它有一个子域profile.stage.mysite.com,但是当我尝试访问它时,它会显示stage.mysite.com的内容.

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

在我的routes.php中,这是代码.

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?

这是我的全部routes.php

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');
});

推荐答案

对于将来的参考,以下是答案和概念:

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

在尝试在应用程序级别分析问题之前,请确保您可以使用子域ping您的服务器.

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

解决之后,这里的陷阱与防火墙和NAT的原理相同:限制越多越重要.在这种情况下,子域将显示与主域相同的信息,因为在 routes.php 文件中,首页/首先被声明了.

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.

这篇关于laravel 5子域重定向到主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆