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

前端 未结 16 4063
温柔的废话
温柔的废话 2021-02-09 18:30

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

相关标签:
16条回答
  • 2021-02-09 18:35

    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
    
    0 讨论(0)
  • 2021-02-09 18:36

    Checking the permissions of wp-login.php revealed that they too had somehow been set to 664 - the same permissions that caused index.php to fail and caused the 500 server error.

    I changed the permissions of wp-login.php to 644 and hey presto, the WordPress login page showed up.

    But on logging in, another redirect loop. So, once again, looking at /wp-admin/index.php, the permissions were 664 rather than 644.

    Fixing them led to problems with the next files in line - the dashboard was a right mess. One by one, changing from 664 to 644 corrected the issues (/wp-admin/load-scripts.php, /wp-admin/load-styles.php).

    So it became obvious that a recursive change of permissions was the only way to sort things out.

    My UNIX isn't exactly top notch, but this appears to have worked (running from Mac OS X Terminal). I ran it from the root directory of this WP install.

    find . -type f -perm 664 -print -exec chmod 644 {} \;
    

    There might be a better command, but I understand this to mean "find all files with 664 permissions and change them to 644".

    It has fixed my problem.

    0 讨论(0)
  • 2021-02-09 18:38

    I just had to flush my redirects. Since I couldn't access the Admin I added this to the top of my functions.php file:

    flush_rewrite_rules(); exit;

    Saved it and refreshed my site. Then remove the code from your functions.php file and then refresh again. That did it for me.

    I also think it might be a good measure to resave your permalinks.

    PS. I think the main issue came from theme-my-login as it was redirecting to /login.

    0 讨论(0)
  • 2021-02-09 18:38

    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

    0 讨论(0)
  • 2021-02-09 18:42

    if your webserver is nginx,you may need check the configure file of your nginx. If there is

    if (!-f $request_filename){
        rewrite ^/(.+)$ /index.php?$1& last;
    }
    

    Replace these lines with

    try_files $uri $uri/ /index.php?$args;
    

    See also Nginx Pitfalls , WordPress wiki page on nginx

    0 讨论(0)
  • 2021-02-09 18:42

    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;
    }
    
    0 讨论(0)
提交回复
热议问题