简体   繁体   中英

Laravel Wildcard Subdomain routing

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 domain@gmail.com
    DocumentRoot "C:\xampp\htdocs\Project\public"
    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:\Windows\System32\drivers\etc\hosts

127.0.0.2 mydomain.com
127.0.0.2 *.mydomain.com

What am I doing wrong?

EDIT: I'm using Windows

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM