apache - 如何确保 Apache 始终通过 HTTPS 提供单个页面?

标签 apache mod-rewrite ssl mod-alias

我想将所有连接从 htt_p://www.example.com/abc.html 重定向到 HTTP_S://www.example.com/abc.html 。哪些 mod_alias 或 mod_rewrite 命令适用于此?我试过:

RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteRule $abc\.html^ https://www.example.com/abc.html [R]

在 .htaccess 和 httpd.conf 中,但这不起作用。如果 RewriteRule 中的第一个字符串是其他任何内容(如 abz.html),它会起作用,但如果它是 abc.html,则不起作用。 abc.html 是服务器上的真实文件(不是另一个重定向)。选项 FollowSymlinks 存在于相应的目录指令中。

非常感谢。

最佳答案

以下内容将允许您将非 SSL 页面重定向到 SSL 版本(假设您在端口 443 上运行 SSL):

RewriteEngine on

# Limited redirects
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} ^/abc\.html$ [OR,NC]
RewriteCond %{REQUEST_URI} ^/def\.html$ [OR,NC]
RewriteCond %{REQUEST_URI} ^/ghi\.html$ [NC]
RewriteRule ^/(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond 之后的 [OR] 标志实际上是“或”,这就是为什么最后一个条件没有它的原因

关于apache - 如何确保 Apache 始终通过 HTTPS 提供单个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2292919/

相关文章:

python - 使用 Apache mod_wsgi 进行 HTTP 流传输

regex - .htaccess 用于 SSL?

node.js - 哪个是在 ubuntu 16.04 中同时安装 Nginx 和 apache 的最佳方式

Apache mod_rewrite 和 Tomcat 摘要认证

delphi - 在 "Poodle"更改后让 Indy 调用与 Paypal IPN 一起工作

ruby-on-rails - 使用 Apache、Puma、Ubuntu 设置 Rails SSL

php - WordPress SEO 友好的 url 是否可以在不使用 htaccess 的情况下工作?

apache - .htaccess - 通用规则

docker - 通过 nginx websocket 代理连接时 WebApp 崩溃

ssl - 如何将 X.509 v1 证书转换为 X.509 版本 3