how to use the laravel subdomain routing function

后端 未结 2 1090
一向
一向 2020-12-14 12:11

I am using the following code its from the laravel 4 site

Route::group(array(\'domain\' => \'{account}.myapp.com\'), function() {

    Route::get(\'user/{         


        
相关标签:
2条回答
  • 2020-12-14 12:38

    Remove user/{id} and replace it with / and then use the following url https://accountname.myapp.com and it will redirect to https://www.myapp.com/accountname

    Route::group(array('domain' => '{account}.myapp.com'), function() {
    
        Route::get('/', function($account, $id) {
            // ...
            return Redirect::to('https://www.myapp.com'.'/'.$account);
        });
    
    });
    

    Edit the answer to the correct answer

    0 讨论(0)
  • 2020-12-14 12:46
    Route::group(array('domain' => '{account}.myapp.com'), function() {
    
        Route::get('/', function($account) {
            // ...
            return Redirect::to('https://www.myapp.com/'.$account);
        });
    
    });
    

    as Marc vd M answer but remove $id from get's closure function.

    why use 'https://www.myapp.com'.'/'.$account and not 'https://www.myapp.com/'.$account

    0 讨论(0)
提交回复
热议问题