laravel - 带有强制 HTTPS 的 Laravel .htaccess
问题描述
我在我的 Laravel 网站的根目录中使用这个 .htaccess 文件进行托管,因此访问者在 URL 地址中看不到 /public/:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^my-domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.my-domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
但到目前为止,我找不到添加强制 HTTPS 重定向的简单解决方案。请问有什么建议吗?
解决方案
使用以下代码修改您的 .htaccess:
<IfModule mod_rewrite.c>
Options -Indexes
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
</IfModule>
推荐阅读
- objective-c - 在 drawatpoint 处使用多种字体颜色设置 UILabel
- mysql - 如何将具有急切加载的雄辩查询更改为简单的 mysql 查询
- c# - 有没有办法使用 pdfsharp 项目修复 Linux 上的 user32.dll 错误?
- flutter - 带有圆角的 Flutter WebView
- image-processing - 如何从图像中去除大颗粒噪声?
- node.js - 在 NodeJS 中的 Fabric 1.4 中将 google.protobuf.Timestamp 转换为 ISO 格式
- string - 如何确保字符串被赋予正确的格式
- android - 批量更新时会触发多少次 onUpdate 函数?
- python - 如何通过删除 for 循环使代码更快
- odoo - 无法在自定义模块中为普通用户创建记录(只能由管理员访问权限创建)