0

So basically my issue is about the routing of a subdomain (or multiple ones) to a single Laravel app. To go more in details I have multiple Route::group and I want to have them "connect" to a specific subdomain. For example:

  • account.domain.co → Route::domain('account.domain.co')→group(...
  • visual.domain.co → Route::domain('visual.domain.co')→group(...

I have configured my Virtual Hosts like so:

<VirtualHost *:443>
    ServerName domain.co
    DocumentRoot /var/www/domain/public
    DirectoryIndex index.php
    [...]
</VirtualHost>

<VirtualHost *:443>
    ServerName account.domain.co
    DocumentRoot /var/www/domain/public
    DirectoryIndex index.php
    [...]
</VirtualHost>

<VirtualHost *:443>
    ServerName visual.domain.co
    DocumentRoot /var/www/domain/public
    DirectoryIndex index.php
    [...]
</VirtualHost>

As you can see, all the DocumentRoot are the same. In theory with the Laravel configuration explained earlier it should work, but in reality account.domain.co, visual.domain.co and domain.co redirect all to the same application instead of their specific Route::group.


Here is the web.php of my app

Route::get('/', 'IndexController@index')→name('index');
[...]

Route::group([ 'domain' => 'account.domain.com', ],function() {
  Route::get('/', 'AccountController@index')→name('account.index');
  [...]
});

Route::group([ 'domain' => 'visual.domain.com', ],function() {
  Route::get('/', 'VisualController@index')→name('visual.index');
  [...]
});

My configuration is: PHP 7.3, Debian 8 (jessie), Apache 2.4.10 and Laravel 5.8.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Hugo
  • 3
  • 5
  • 1
    Could you include your complete(obfuscated) Routes and Group definitions. It is impossible to diagnose an ellipsis. –  Jun 30 '19 at 19:03
  • Sure @Strom , just edited the original post to include the web.php example – Hugo Jun 30 '19 at 19:09

1 Answers1

0

You are defining Route::groups without calling them. For this example you probably don't need the groups at all; the documentation is unclear as to that point. I have included them since it will not hurt anything.

The first two are for the default domain access methods (replaces the first route get('/') which was the only one taken in your code).

Route::domain('www.domain.com')->group(function() {
get('/', 'IndexController@index')->name('index');
})};

Route::domain('domain.com')->group(function() {
get('/', 'IndexController@index')->name('index');
})};

Route::domain('account.domain.com')->group(function() {
  Route::get('/', 'AccountController@index')->name('account.index');
})};

Route::domain('visual.domain.com')->group(function() {
  Route::get('/', 'VisualController@index')->name('visual.index');
})};
//...
  • Oh ok so from what I understand I should group everysingle route even and set a « domain » to them, right ? – Hugo Jul 01 '19 at 04:56
  • Just tested it, and I have to say that you saved me from another headache. Thank you very much for your precious help! – Hugo Jul 01 '19 at 08:07