2

我想将所有连接从 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 存在于相应的目录指令中。

非常感谢。

4

1 回答 1

1

以下内容将允许您将非 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] 标志字面意思是“或”,这就是最后一个条件没有它的原因

于 2010-02-19T00:27:28.897 回答