在 laravel 中通过 https 仅加载一页的最佳方法是什么?
What is the best way to load only 1 page over https in laravel?
在我的 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 加载我的所有资产。这意味着我的所有资产都将在我的主人 blade 中有这样的东西:
@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/page - 我觉得这很干净。
示例:
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 ^(.*)/$ / [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)
助手。
在我的 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 加载我的所有资产。这意味着我的所有资产都将在我的主人 blade 中有这样的东西:
@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/page - 我觉得这很干净。
示例:
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 ^(.*)/$ / [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)
助手。