.htaccess - 将 HTTP 重定向到 HTTPS Htaccess

标签 .htaccess http redirect https

我需要一个脚本来 .htaccess 来 301 重定向 http 到 https,但是一个页面需要通过 HTTP 访问。示例:

example.com/* 重定向到 https://example.com/*
example.com/page1 不重定向到 https://example.com/page1

最佳答案

只需使用这个:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

因此它只会将所有页面的 SSL 设置为 https,即使有人通过 http 访问它也是如此。

如果你想对目录/page1 以外的所有内容强制使用 https

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !page1 [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

关于.htaccess - 将 HTTP 重定向到 HTTPS Htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37797082/

相关文章:

.htaccess - 无法将缓存控制设置为公共(public) .js、.css 和图像文件

http - 是否可以在不干扰服务器的情况下使用 Charles 代理或任何其他工具故意生成错误 500

具有请求授权的 HTTP 缓存

redirect - 如何将子域的所有页面永久重定向到 www 域的子路径?

.htaccess - htaccess 手动重定向到重命名的 "Main Page"

wordpress - 如何为我的 Wordpress 网站访问我在 Google Cloud 上的 .htaccess 文件?

linux - 本地 Ubuntu 服务器上的 URL 重写不起作用

Apache 在使用 mod_proxy 时忽略重写规则

c# - Mjpeg VLC 和 HTTP 流媒体

java - 未将 JAX-RS 自定义 header 添加到重定向响应