[英]How to fix the HTTPS Wordpress wp-admin redirect loop
I know there is a lot of questions like this but none has given me an answer that resolved my problem with my WordPress wp-admin/ page, the browser throws an ERR_TOO_MANY_REDIRECTS error, I have disabled all plugins, cleared my cache and cookies, edited my wp-config.php file but still nothing. 我知道有很多这样的问题,但是没有一个给我一个答案,可以解决我的WordPress wp-admin /页面问题,浏览器抛出ERR_TOO_MANY_REDIRECTS错误,我禁用了所有插件,清除了缓存和cookie,进行了编辑我的wp-config.php文件,但是什么也没有。
my apache config: 我的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>
my wp-config.php 我的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';
my $_SERVER variable: 我的$ _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
)
In some setups HTTP_X_FORWARDED_PROTO
contains a comma seperated list. 在某些设置中, HTTP_X_FORWARDED_PROTO
包含逗号分隔的列表。 (ex http,https
) (例如http,https
)
This seems to be the case in your setup. 在您的设置中似乎是这种情况。 Checking that HTTP_X_FORWARDED_PROTO contains the string https
instead of checking that it equals https
should do the trick. 检查HTTP_X_FORWARDED_PROTO包含字符串https
而不是检查它是否等于https
应该可以解决问题。
Try the following: 请尝试以下操作:
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';
Side note: You can safely ignore this part of your check: (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')
旁注:您可以放心地忽略检查的这一部分: (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.