我知道有很多这样的问题,但是没有一个给我一个答案,可以解决我的WordPress wp-admin /页面问题,浏览器抛出ERR_TOO_MANY_REDIRECTS错误,我禁用了所有插件,清除了缓存并cookie,编辑了我的wp-config.php文件,但仍然没有。
我的Apache配置:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / "https://example.com/"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www>
AllowOverride None
Order Allow,Deny
Allow from All
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php
</IfModule>
</IfModule>
</Directory>
</VirtualHost>
</IfModule>
我的wp-config.php
define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');
/** SSL */
define('FORCE_SSL_ADMIN', true);
if((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';
我的$ _SERVER变量:
Array
(
[SERVER_SOFTWARE] => Apache/2.4.29 (Ubuntu)
[REQUEST_URI] => /wp-admin/?test=1
[REDIRECT_HTTPS] => on
[REDIRECT_SSL_TLS_SNI] => example.com
[REDIRECT_STATUS] => 200
[HTTPS] => on
[SSL_TLS_SNI] => example.com
[HTTP_HOST] => example.com
[HTTP_CONNECTION] => keep-alive
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
[HTTP_DNT] => 1
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
[HTTP_ACCEPT_ENCODING] => gzip, deflate, br
[HTTP_ACCEPT_LANGUAGE] => es-ES,es;q=0.9,en;q=0.8,pt;q=0.7
[HTTP_COOKIE] => PHPSESSID=84c3jbfdtbmcl4jnibgobm3666
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[SERVER_SIGNATURE] =>
Apache/2.4.29 (Ubuntu) Server at example.com Port 443
[SERVER_NAME] => example.com
[SERVER_ADDR] => xxx.xxx.xxx.xxx
[SERVER_PORT] => 443
[REMOTE_ADDR] => xxx.xxx.xxx.xxx
[DOCUMENT_ROOT] => /var/www
[REQUEST_SCHEME] => https
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /var/www
[SERVER_ADMIN] => [no address given]
[SCRIPT_FILENAME] => /var/www/index.php
[REMOTE_PORT] => 52242
[REDIRECT_URL] => /wp-admin/
[REDIRECT_QUERY_STRING] => test=1
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => test=1
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1550424580.519
[REQUEST_TIME] => 1550424580
)
答案 0 :(得分:0)
在某些设置中,HTTP_X_FORWARDED_PROTO
包含一个逗号分隔的列表。 (例如http,https
)
在您的设置中似乎是这种情况。检查HTTP_X_FORWARDED_PROTO是否包含字符串https
而不是检查它是否等于https
即可。
尝试以下操作:
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';
旁注:
您可以放心地忽略支票的这一部分:(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')