我在我的一台机器上设置phpMyID,并且我只是在提交密码时尝试让apache重定向到HTTPS。我正在这样做,因为我重新定向所有openid流量的原始设置不起作用stackoverflow不喜欢我的自签名证书。这是我写的新规则,但它不起作用:

RewriteRule http://%{SERVER_NAME}/openid/index.php(\?.+)$ https://%{SERVER_NAME}/openid/index.php$1
有帮助吗?

解决方案

您需要使用Cond来测试端口(http或httpd)和查询字符串:

RewriteCond %{SERVER_PORT} 80
RewriteCond %{QUERY_STRING} (.+)
RewriteRule /openid/index.php https://%{SERVER_NAME}/openid/index.php?%1

如果在.htaccess上,则必须使用

RewriteCond %{SERVER_PORT} 80
RewriteCond %{QUERY_STRING} (.+)
RewriteRule openid/index.php https://%{SERVER_NAME}/openid/index.php?%1

其他提示

更好的解决方案是:

    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^openid/index\.php$ https://%{SERVER_NAME}/openid/index.php

解释: RewriteCond%{SERVER_PORT} 80 也匹配仅包含 80 的端口。这同样适用于模式 openid / index.php (其中“ ”也可以是任何字符)。并且附加查询是没有必要的,因为除非给出替换的查询,否则mod_rewrite会自动将最初请求的查询附加到替换。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top