我想将所有连接从 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/