sujit prasad
sujit prasad

Reputation: 945

Laravel project on a single domain with multiple sub-domain on the same laravel project

I have a laravel website that has domain name eg:- www.website.com

but on the other hand I am trying it to make accessible to two more domain names

eg:- aaa.website.com and bbb.website.com

and also I want to be able to fetch the subdomain names from where these has been accessed.

thank you.

Upvotes: 2

Views: 2288

Answers (1)

ceejayoz
ceejayoz

Reputation: 180004

If you want www, aaa, and bbb to all have the same routes/content, you don't really have to do anything in Laravel. You'd just need to setup your Apache/nginx config's virtual hosts to serve the same code to all three.

For different routing per-subdomain, you can use Laravel's subdomain routing.

Route::group(['domain' => '{sub}.example.com'], function() {
    Route::get('user/{id}', function($sub, $id) {
        //
    });
});

If you just want to fetch the subdomain name without dealing with a routing group, Request::getHost() will give you the hostname, which you can parse as desired.

Upvotes: 4

Related Questions