'how to run multiple domains (or sub-domain) on one Laravel app

I want to host multiple site with shared pages and functionality but don't want redirection

web.php

Route::get('/', function () {
    return "site 1";
});

Route::domain('site2.test')->group(function () {
    Route::get('/', function () {
        return "site 2";
    });
});

domain 1 preview

domain 2 preview

C:\Windows\System32\drivers\etc\hosts

127.0.0.1 site1.test
127.0.0.1 site2.test

C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs/multidomain/public"
    ServerName  site1.test
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs/multidomain/public"
    ServerName  site2.test
</VirtualHost>


Solution 1:[1]

"In order to ensure your subdomain routes are reachable, you should register subdomain routes before registering root domain routes. This will prevent root domain routes from overwriting subdomain routes which have the same URI path." (source)

You'll need to just move your Route::domain() to the top.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sykez