Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache仅在输入密码时重定向_Apache_Mod Rewrite_Phpmyid - Fatal编程技术网

Apache仅在输入密码时重定向

Apache仅在输入密码时重定向,apache,mod-rewrite,phpmyid,Apache,Mod Rewrite,Phpmyid,我在我的一台机器上设置了phpMyID,我试图让apache仅在提交密码时重定向到HTTPS。我这样做是因为我最初重定向所有openid流量的设置不起作用。stackoverflow不喜欢我的自签名证书。这是我写的新规则,但它不起作用: RewriteRule http://%{SERVER_NAME}/openid/index.php(\?.+)$ https://%{SERVER_NAME}/openid/index.php$1 您需要使用Cond测试端口(http或httpd)和查询字符

我在我的一台机器上设置了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 重写cond%{SERVER\u PORT}^443$ 重写规则^openid/index\.php$https://%{SERVER\u NAME}/openid/index.php
解释:
RewriteCond%{SERVER\u PORT}80
也匹配只包含
80
的端口。这同样适用于模式
openid/index.php
(其中“
”也可以是任何字符)。并且不需要追加查询,因为mod_rewrite会自动将最初请求的查询追加到替代项,除非给出了替代项的查询。

请注意,这实际上不适用于获取phpMyID,因为在验证堆栈溢出时,它会使用查询字符串重定向到自身。这是一个好的开始。