php - 如何强制http到https
问题描述
我有一个移动应用程序,其 API 是用 laravel 构建的。url 是通过 http 请求完成的,但是服务器已更新为使用 https。我想在我的 htaccess 中强制我的请求从 http 到 https。我在这里检查了许多类似的问题,但我似乎没有改变线路来实现这一点,因为我看到了不同的解决方案,而且我的 htaccess 文件看起来与其他文件不完全相同。
这是我的文件:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
解决方案
尝试在 RewriteEngine On 之后添加以下脚本并尝试一下。
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
推荐阅读
- eclipse - 选择不包含编译单元
- c# - C# 从 HTML Body 解析 XML 并保存到文件
- arm - 奇怪的 ROS 安装行为
- android - Android Q 中的 Firebase 电话身份验证
- reactjs - 在我的项目中安装 antdesign 后如何修复 webpack 构建错误,bezierEasingMixin()?
- bash - 如何将字体颜色和样式从 bash 变量传递到 PS1 提示符
- java - Java AWT 绘制瓷砖 laves gap
- heroku - WickedPDF 图像未出现在 heroku 的生产中
- google-sheets - 基于动态组的数学
- html - Responsive navbar icon absolute position not working