代码之家  ›  专栏  ›  技术社区  ›  lin

Laravel4.2:强制将URL呈现为HTTP或HTTPS

  •  3
  • lin  · 技术社区  · 7 年前

    我们有一个简单的路线定义如下:

    路线

    // Home
    Route::get('/home', [
        'as' => 'home::index',
        'uses' => 'IndexController@home'
    ]);
    

    视图

    <a href="{{ route('home::index') }}">Home</a>
    

    我们需要在呈现为HTTP或在某些情况下呈现为HTTPS路由的视图中强制我们的链接/路由。 http://host.domain/home https://host.domain/home .

    我们不能使用 URL::forceSchema("http") URL::forceSchema("https") 因为我们需要在HTTP页面上强制使用HTTPS,而在HTTPS页面上强制使用HTTP。我们有一个多域应用程序。有些域通过HTTP运行,有些域通过HTTPS运行。到不同域/应用程序部分的链接可以放在任何地方。通过https运行的域不能通过http访问。在HTTP上运行的域无法通过HTTPS访问

    如何强制将路由呈现为特定的超文本协议?

    1 回复  |  直到 7 年前
        1
  •  2
  •   lin    7 年前

    Laravel documentaion Illuminate\Routing\UrlGenerator getRouteScheme http https


    Route::get('/home', [
        'as' => 'home::index',
        'uses' => 'IndexController@home',
        'http'
    ]);
    

    Route::get('/home', [
        'as' => 'home::index',
        'uses' => 'IndexController@home',
        'https'
    ]);
    

    route('home::index')

    推荐文章