Ad

Laravel Routing To Subdomain

- 1 answer

I am using Laravel 5.7. Currently have all the route go through Api.php, web.php, and website.php. In live version of the app, there is a subdomain pointing to website.php is [anything].websiteaddress.com, and domain www.websiteaddress.com is pointing web.php. In local environment, how can I access subdomain using localhost:8000. I have tried to use [anything].websiteaddress.com, it does not work. What is proper way to access subdomain?

Ad

Answer

1.Configure in Web server httpd.conf create virual Host ip or name what you want

<VirtualHost *:80>

 ServerName website.com

 ServerAlias *.website.com

</VirtualHost>

2.route configuration like

Route::group(array('domain' => '{account}.website.com'), function() {

    Route::get('/', function($account, $id) {
        // ...
        return Redirect::to('https://www.website.com'.'/'.$account);
    });

});
Ad
source: stackoverflow.com
Ad