简体   繁体   中英

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?

Update :

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.

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.

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