skip to Main Content

I have some problems with wildcard subdomain routing with Laravel.
I want to create subdomain for every user.
So I’m doing like this:

My API.js in Laravel routes:

    Route::domain('{user}.mydomain.com')->group(function () {
        Route::get('user', [UserController::class, 'getUserDetails'])->name('user'); 
    });

And this is my vhosts

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:xampphtdocsProjectpublic"
    DirectoryIndex index.php
    ServerName mydomain.com
    ServerAlias *.mydomain.com

    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

And C:WindowsSystem32driversetchosts

127.0.0.2 mydomain.com
127.0.0.2 *.mydomain.com

What am I doing wrong?

EDIT: I’m using Windows

2

Answers


  1. Windows does not support wildcard entries in the hosts file. You’ll need to specify alle the individual subdomains.

    Login or Signup to reply.
  2. You simply need a DNS service. i use Acrylic DNS Proxy on Windows and they have a nice documentation how to setup in windows environment.

    Link for Acrylic Documentation

    Simply follow the documentation and add your hosts in Acrylic UI host configuration at the bottom as listed here

    127.0.0.1 *.mydomain.com domain.com
    

    Don’t forget to restart Acrylic DNS Proxy service after setting up, should work like a charm.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search