繁体   English   中英

如何强制 http 为 https

[英]How to force http to 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 [LR=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] 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM