在我的laravel应用程序中,我需要一个页面通过https,因为我希望用户使用他的麦克风。
方法getUserMedia和当前仅允许通过httpshttps://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins
为了性能,我只希望这个做音频录制的页面是通过https。但这也意味着我需要通过https加载我的所有资产,只在这个页面中使用"secure_asset"。这意味着我所有资产的主刀中都会有这样的东西:
@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路由实现这一点的最佳和最干净的方法是什么?
在routes.php
中使用'https' => true]
只用于这一条路线/页面-这对我来说似乎很干净。
示例:
Route::post('/yourroute', ['uses' => 'YourController@method', 'https' => true]);
更新您也可以使用public
文件夹中的.htaccess
文件。
<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)
辅助对象。