how to use the laravel subdomain routing function

喜欢而已 提交于 2019-12-18 01:22:25

问题


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

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

    Route::get('user/{id}', function($account, $id) {
        // ...
     return Redirect::to('https://www.myapp.com'.'/'.$account);
    });

});

the idea is to redirect subdomain.myapp.com to myapp.com/user/subdomain .what I have is not working any suggestions?sorry I just started with laravel about a month now.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/21326980/how-to-use-the-laravel-subdomain-routing-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!