在PHP或.htaccess中检测HTTPS代理

时间:2018-01-29 13:55:27

标签: php apache .htaccess https

我在apache服务器配置中设置了ProxyPass

PHP似乎无法检测到HTTPS。

如果不是.htaccess中的HTTPS,我如何检测PHP中的HTTPS或重定向?

Apache配置:

<IfModule mod_ssl.c>
<VirtualHost *:443>

ServerName domain.co.uk
ServerAlias www.domain.co.uk
ProxyPass / http://external-domain.com/

Include /etc/letsencrypt/options-ssl-apache.conf
...

</VirtualHost>
</IfModule>

2 个答案:

答案 0 :(得分:2)

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

来源:https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

答案 1 :(得分:0)

如果你使用HTTPS,这将检查PHP。

if(!empty($_SERVER["HTTPS"])) { 
}