【问题标题】:how to use the laravel subdomain routing functionlaravel子域路由功能如何使用
【发布时间】:2014-02-15 02:40:06
【问题描述】:

我正在使用来自 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);
    });

});

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

【问题讨论】:

  • 您尝试的网址是什么?我猜你应该删除user/{id} 并用/ 替换它,然后转到fogsy.myapp.com
  • 有时我会很笨...谢谢@MarcvdM
  • 你解决了这个@cppit 吗?

标签: laravel laravel-4


【解决方案1】:
Route::group(array('domain' => '{account}.myapp.com'), function() {

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

});

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

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

【讨论】:

    【解决方案2】:

    删除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);
        });
    
    });
    

    修改答案为正确答案

    【讨论】:

    • 对不起,这不是答案,如果您直接重定向子域,则不会使用子域
    • 我想用它从www.mydomain.com重定向到mydomain.com。是301重定向吗?
    猜你喜欢
    • 2018-01-06
    • 2017-10-13
    • 1970-01-01
    • 2015-04-23
    • 2018-03-01
    • 2020-01-04
    • 2016-09-18
    • 2016-09-25
    • 2015-09-10
    相关资源
    最近更新 更多