search

Home  >  Q&A  >  body text

Define both the Subdomain and the url to point to a controller in Laravel

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:

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粉546257913P粉546257913454 days ago646

reply all(1)I'll reply

  • P粉553428780

    P粉5534287802023-09-16 14:34:54

    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.

    reply
    0
  • Cancelreply