.htaccess - 如何在 .htaccess 中强制使用 ssl

标签 .htaccess ssl

我在我工作的平台上已经有了这个 .htaccess 文件,我们安装了 ssl 证书,我们希望所有网站都使用 https,如何在不影响其他规则的情况下做到这一点

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ /index.php/$1 [QSA,L]

Options -Indexes

我在此处和其他网站的一些答案中看到了一些用于执行此操作的代码,但我不知道将其添加到何处以及它将如何影响该网站,该网站是实时的并且不能被弄乱,

谢谢大家的帮助

最佳答案

你可以这样做:

Options -Indexes
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /index.php/$1 [QSA,L]

关于.htaccess - 如何在 .htaccess 中强制使用 ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22833549/

相关文章:

c# - 连接到 ftps ://URL

php - 带有自签名证书的 POST 请求

php - Laravel 和通过特定 Laravel 路由的双向 SSL

.htaccess - 通过 Htaccess 禁用 SSL 证书 HTTPS 重定向

php - 将 .htaccess 重定向到 ssl 不起作用

.net - 2-Way SSL认证和请求授权

c# - Window Phone 8 中的客户端证书

apache - .htaccess 中的 DirectoryIndex 给出内部服务器错误

php - 无法访问 PHP 基本身份验证变量

ssl - 在openssl req命令行设置证书的参数