Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmadbadpey's avatar

Dynamic sub-domain creation on new User registration in laravel 5 and WampServer

I want to assign a Specific subdomain to each user after registration based on her Username on the local wampServer for a domain like tc.dev

I've done all steps that been said in This Topic or other similar topics on the web.

This is configuration that i added to httpd-vhosts.conf file:

    <VirtualHost *:80>
DocumentRoot "D:/wamp/www/tc/public/"
ServerName tc.dev
ServerAlias *.tc.dev
<directory "D:/wamp/www/tc/public/">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all
</directory>
</VirtualHost>

And this is what I added to C:\Windows\System32\Drivers\etc\hosts file :

127.0.0.1   tc.dev  
127.0.0.1   *.tc.dev

and this is My route :

Route::group(['domain' => '{account}.tc.dev'], function () {
        Route::get('/', function ($account, $id) {
            return view('main.pages.user.index');
        });
    });

tc.dev works fine but any subdomain that I test does not work and index view not shown.

what is problem and solution?

0 likes
6 replies
Erik's avatar

Windows does not support this. You need to register the subdomains manual.

ahmadbadpey's avatar

According to Wildcards in a Windows hosts file ! , now sub-domain works as main domain But based on route that I wrote main.pages.user.index does not show and index.php file in DocumentRoot "D:/wamp/www/tc/public/" Is shown.

It seams this route does not consider.

ahmadbadpey's avatar
ahmadbadpey
OP
Best Answer
Level 2

Finally after Many research and try different ways I could solve problem.

after using Acrylic DNS Proxy , I must use two different root for main and sub domains .

This for Main Domain :

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

And another for handling subdomains :

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

In fact The main thing was that I must to use another Route to control routes that acts On main Domain While I was ignored.

1 like
amitshahc's avatar

but in this tc.dev is hardcoded?

I have my domain name as test1.com on my local pc and on server when i deploy it can be testing.com so how do we manage the dynamic domain (root level domain name) in the route?

nabeelali03411's avatar

@amitshahc you can specify your domain dynamically in config or .env file like this:

APP_URL = tc.dev 

than you can access it in the route

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

or similarly through config:

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

Please or to participate in this conversation.