laravel 如何使用laravel子域路由功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21326980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:43:39  来源:igfitidea点击:

how to use the laravel subdomain routing function

laravellaravel-4

提问by cppit

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

我正在使用来自 laravel 4 站点的以下代码

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.

这个想法是将 subdomain.myapp.com 重定向到 myapp.com/user/subdomain 。我所拥有的没有任何建议?抱歉,我刚开始使用 laravel 大约一个月了。

回答by Marc vd M

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

删除user/{id}并替换它,/然后使用以下网址https://accountname.myapp.com,它将重定向到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

编辑正确答案的答案

回答by etudor

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.

作为 Marc vd M 的回答,但从 get 的闭包函数中删除了 $id。

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

为什么使用'https://www.myapp.com'.'/'.$account而不是'https://www.myapp.com/'.$account