Define both the Subdomain and the url to point to a controller in Laravel
P粉546257913
P粉546257913 2023-09-15 20:13:56
0
1
494

I am developing a Laravel application in which I have simple urls like -domain.com/shop but I want to create two dynamic urls for this like:

  • domain.com/shop
  • shop.domain.com

Both dynamically point to the same url. I want to dynamically define a subdomain url and a simple url pointing to the same page for each user.

P粉546257913
P粉546257913

reply all (1)
P粉553428780

After a lot of research and trying different methods, I finally solved this problem.

After using Acrylic DNS proxy, I have to use two different roots for the main domain and subdomain.

This is the main domain:

// Match my own domain Route::group(['domain' => 'tc.dev'], function() { Route::any('/', function() { return 'My own domain'; }); });

Another one for handling subdomains:

Route::group(['domain' => '{subdomain}.tc.dev'], function() { Route::any('/', function($subdomain) { return 'Subdomain ' . $subdomain; }); });

In fact, the main thing is that I have to use another route to control the route that acts on the main domain, and I am ignored.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!