简体   繁体   English

Laravel中的子域

[英]Subdomains in Laravel

Having problem with subdomains :( 子网域有问题:(

In Routes: 在路线中:

Route::group(['domain' => 'www.app.me'], function(){
    Route::get('/', 'SiteController@index');
    Route::get('/{uri}', 'ShortnerController@redirect');
});
Route::group(['domain' => 'app.me'], function(){
    Route::get('/', 'SiteController@index');
    Route::get('/{uri}', 'ShortnerController@redirect');
});
Route::group(['domain' => 'platform.app.me'], function(){
    Route::get('/', 'PageController@index')->before('auth'); 
});
Route::group(array('domain'=>'agent.app.me'), function(){
Route::get('/', 'AgentController@index')->before('auth');
});

When I go to app.me or www.app.me it shows the SiteController@index If I go to agent.app.me it shows AgentController@index 当我转到app.me或www.app.me时,它会显示SiteController @ index如果我转到agent.app.me,它会显示AgentController @ index

But the problem is if I go to platform.app.me it redirects to app.me 但是问题是,如果我转到platform.app.me,它将重定向到app.me

How to solve this? 如何解决呢?

In cPanel a managed redirections like this: 在cPanel中,托管重定向如下:

Subdomains.Root Domain    Document Root    Redirection
agent.app.me              /public_html     not redirected
platform.app.me           /public_html     not redirected

Try changing the order. 尝试更改顺序。 The first matched route will always be the one used. 第一条匹配的路线将始终是所使用的路线。 Also, if app.me is just going to use the same routes as www., why not use htaccess to force www. 另外,如果app.me仅使用与www。相同的路由,为什么不使用htaccess强制使用www。 and have one less route group to maintain? 少维护一组路线?

So, routes.php: 因此,routes.php:

Route::group(['domain' => 'platform.app.me'], function(){
    Route::get('/', 'PageController@index')->before('auth'); 
});

Route::group(['domain'=>'agent.app.me'], function(){
    Route::get('/', 'AgentController@index')->before('auth');
});

Route::group(['domain' => 'www.app.me'], function(){
    Route::get('/', 'SiteController@index');
    Route::get('/{uri}', 'ShortnerController@redirect');
});

Notice that I changed your use of array() to [] in the agent.app.me route group for consistency as you were mixing the two. 请注意,在混合两者时,为了保持一致性,我在agent.app.me路由组agent.app.me array()使用更改为[]

And .htaccess: 和.htaccess:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    # Enforce www where not using www or a valid sub domain or tld
    RewriteCond %{HTTP_HOST} !^(www|agent|platform)\.app\.(me|dev)$ [NC]
    RewriteRule ^(.*)$ http://www.app.me/$1 [L,R=301]

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM