在laravel中仅通过https加载1页的最佳方法是什么?

时间:2016-05-04 16:27:44

标签: php laravel https getusermedia

在我的laravel应用程序中,我需要一页超过https,因为我希望用户使用他的麦克风。

方法getUserMedia,目前仅允许通过https https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

为了提高性能,我只希望这个录音的页面超过https。但这也意味着我需要使用' secure_asset'加载https上的所有资产。仅在此页面中。这意味着我的主刀片中的所有资产都会有这样的东西:

@if(Request::is('record'))

   <script type="text/javascript" src="{{secure_asset('/js/jquery.js')}}"></script>

@else

   <script type="text/javascript" src="{{asset('/js/jquery.js')}}"></script>

@endif

使用laravel路由实现这一目标的最佳和最干净的方法是什么?

1 个答案:

答案 0 :(得分:1)

'https' => true]中使用routes.php仅针对此一条路线/页面 - 这对我来说似乎非常干净。

示例:

Route::post('/yourroute', ['uses' => 'YourController@method', 'https' => true]);

<强>更新 您还可以使用.htaccess文件夹中的public文件。

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Redirect specific route to HTTPS
    # The rule is looking for the content between ^ and $ and if found in the URL it redirects to https://www.example.com/yourroute
    RewriteRule ^yourroute$ https://www.example.com/yourroute [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

是的,对于您的资产,您需要使用if-else语句。您可以使用secure_asset() asset(..., true)帮助。

相关问题