Cant login to my wp-admin after switching to SSL

47,386

Solution 1

You need to change the site url in wp-admin->Settings->General. Except now you need to go in through phpMyAdmin and do it manually in the wp_options table since you are locked out.

You get different cookies depending on http/https so you are getting the https cookie and then being redirected to http that has no cookie because of your Wordpress settings that say what url the site resides at.

Solution 2

I had the exact same problem with my site on NearlyFreeSpeech.net, and the solution was not so simple as fixing the site URLs. That made no difference.

The underlying problem in my case, and the solution, were explained in the post copied below. Note that on my system, the SSL error created two problems, the one described here on Stack Overflow (wp-login refreshes without logging in) and a failure of WP to load stylesheets, which was the problem actually addressed in the forum post quoted below. The solution in the post solves both problems.

What you describe sounds like the browser refusing to load the stylesheet, which typically happens when first creating an HTTPS-enabled WordPress site or adding SSL/TLS to an existing WP site.

WordPress isn't very smart about "reverse proxies" like what NFSN uses, where the user hits an outer web server that then talks to an inner application server where WordPress actually lives.

If you think you have an SSL-enabled site, especially if it's a new one, this could be your problem. You would need to edit your wp-config.php file to add the following:

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';

just above the "That's all, stop editing! Happy blogging!" lines.

Conversely, if you don't think you are using SSL on your site, this won't do anything. Check the alias for your site on the NFSN site control panel. If you see a padlock, you're set up in NFSN and need the code above.

WordPress's implementation of SSL is kind of a botch. It not only doesn't recognize SSL under environments like ours - it also is prone to redirect loops if everything isn't changed in exactly the right order. If the code above causes a site outage - you keep getting complaints from the browser about redirect loops - then remove the code and ask again. I'll see if I can find my notes about how to do initial SSL setup.

Solution 3

It is possible to set the site URL manually in the wp-config.php file.

Add these two lines to your wp-config.php, where "example.com" is the correct location of your site.

define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');

For more refer here

or check in table wp_options column option_name = siteurl check the option_value

Solution 4

I have used this first:

i have

if (
    isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && 
    $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https"
) {
    $_SERVER["HTTPS"] = "on";
}

still not able to fix and nothing happened.

Then I used

define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');

and I was able to connect to wp with https.

Now I have only minor issues of conflict (mixed https/http content on my page) but most things work.

Thank you!

Share:
47,386
user1269625
Author by

user1269625

Updated on July 09, 2022

Comments

  • user1269625
    user1269625 almost 2 years

    I recently installed SSL certificate for my wordpress site(http to https) and now I'm unable to access Wordpress Admin. It refreshes the page and I am not logged in.

    Is there something I forgot to change in my wordpress files?

    I inspected the code and the login form is pointing to my old site (the http one) and when I look at the code in the file, the form action is set to site_url() and I can't seem to find where it's defined.

  • user1269625
    user1269625 over 11 years
    So I went into PhpMyAdmin and changed the site url in wp_options and cleared my cache and cookies and still was unable to login :(
  • Emery King
    Emery King over 11 years
    there are 2 spots it wp_options to update. look for the other.
  • Emery King
    Emery King over 11 years
    click "search" and with the value column search http://% with "LIKE" selected. If you get any results with your domain, change them to https.
  • Emery King
    Emery King over 11 years
    If you intend on your entire site being https then i don't see why not.
  • user1269625
    user1269625 over 11 years
    I have changed all of those and I must say it fixed a few display issues I was having which is why I needed to login in the first place, but anyways after clearing my broswer and cache I am still unable to login.
  • Emery King
    Emery King over 11 years
    Make sure cookies are enabled in your browser, make sure there isn't any confusion with www./no www., Verify you have the right credentials, and check your .htaccess file for anything referencing port 80 or http:// directly. I'm too blind to help you.
  • user1269625
    user1269625 over 11 years
    Would it be safe to post whats on my .htaccess file on here? this is what returns in my url ?redirect_to=http%3A%2F%2Fwww.mysite.com%2Fwp-admin%2F&reaut‌​h=1
  • Emery King
    Emery King over 11 years
    that looks like a bad authentication. verify your password somehow.
  • user1269625
    user1269625 over 11 years
    When I enter in a wrong password I get an error ERROR: The password you entered for the username admin is incorrect. when I enter in the correct password I get redirected back to the sign in page.
  • user1269625
    user1269625 over 11 years
    This issue is fixed by going into wp_login_redirects in phpMyAdmin and changing http to https :)
  • Noushad
    Noushad over 7 years
    i have if (isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https") $_SERVER["HTTPS"] = "on"; still not able to fix.
  • marca
    marca almost 6 years
    Thanks, this did fix it for me
  • Ayoub Laazazi
    Ayoub Laazazi over 5 years
    You saved me:)!
  • Borislav Stoilov
    Borislav Stoilov over 4 years
    I was able to resolve the mixed content issues, using one of the plugins available for this.
  • MangoLassi
    MangoLassi almost 3 years
    This helped me get into my wordpress site. In my case I had gone into cloudflare and set SSL to "flexible" and in wordpress in Settings changed the site URLs to use https. After that I got the too many redirects error and couldn't log in. I was able to use the above fix except I used it to set my URLs to just "http". I then logged into wordpress, went to settings, was able to remove the lines from the wp-config file, and reset the URLs to just http. I then went into cloud flare and set SSL to Full mode. Everything works now. I feel lucky.