Redirect loop on wp-admin or wp-login.php

2019-03-30 08:27发布

I put together a quick WordPress site locally using MAMP, then checked it into an SVN repo. I then checked it out on to my development server.

I didn't change anything except to run the search and replace tool script from Interconnectit to updated the URL of the site in the database on the server.

Initially, I got a 500 server error. Checking the logs, I discovered that this "SoftException" was because index.php was writeable by group - the permissions were 664. No problem - a quick change of permissions to 644 sorted that. So now the frontside was working.

However, strangely, the admin side of the site did not work. It just produced an endless redirect loop in all browsers.

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

Nothing has changed since the local development version. The htaccess file is just a standard WordPress one. Nothing weird... still working fine locally.

So what's going on?

14条回答
Anthone
2楼-- · 2019-03-30 08:39

I faced same problem after I restore backup from other server , it was promissing issue I solve it this way .

  chown -R www-data:www-data          /var/www
  chmod -R g+rwx                     /var/www
  chmod -R 0755                      /var/www

Where /var/www the place to store website files , replace it with suitable path acurding to your configuration , eg /usr/share/nginx/www << default Nginx

查看更多
三岁会撩人
3楼-- · 2019-03-30 08:40

For whatever reason /wp-admin/ path causes a redirect loop, but /wp-admin/index.php does not. As such, we can use .htaccess to redirect the /wp-admin/ path to /wp-admin/index.php by adding the following line to your .htaccess file after "RewriteBase /" line like this:

RewriteBase /
RewriteRule  /wp-admin/ /wp-admin/index\.php [L,P]

It worked for me like that. You final .htaccess would probably look like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule  /wp-admin/ /wp-admin/index\.php [L,P]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
查看更多
叛逆
4楼-- · 2019-03-30 08:40

In the sites-enabled folder you will need to edit the configuration for your site and add the multisite redirection rules. For Ubuntu 14.04 you will be able to find the path under /etc/nginx/sites-available

Add the following block in your server block and you should be able to avoid the infinite redirection loop.

#Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
查看更多
乱世女痞
5楼-- · 2019-03-30 08:42

If you're using Cloudflare you might want to try adding this to the TOP of your wp-config.php file:

define('WP_SITEURL', 'https://www.example.com');
define('WP_HOME', 'https://www.example.com');
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
if(isset($_SERVER['HTTP_CF_VISITOR']) && strpos($_SERVER['HTTP_CF_VISITOR'], 'https')){
  $_SERVER['HTTPS']='on';
}

It's important that you add it to the top of the wp-config.php file or you'll end up with "Sorry, you are not allowed to access this page" error messages.

Credit: https://www.meltajon.com/dev/wordpress-wp-admin-redirect-loop-with-cloudflare-ssl

查看更多
【Aperson】
6楼-- · 2019-03-30 08:50

with nginx config I had originally only this line and experienced the same redirect issue:

location / {
    try_files   $uri /index.php$is_args$args;
}

after adding this everything was fine:

location /wp-admin/ {
    index index.php;
    try_files $uri $uri/ /index.php$args;
}
查看更多
太酷不给撩
7楼-- · 2019-03-30 08:53

If you have nginx, then also check your index config. As for me I had an issue: I've set the following:

server {
    server_name _;
    root /var/www/html;
    index /index.php;
}

So as you see I've set index.php with trailing slash, which means that all rewrite requests will go to the index.php in document_root. For WP it's wrong, because wp-admin directory has its own index.php

查看更多
登录 后发表回答