Cant login to my wp-admin after switching to SSL

2020-02-26 09:43发布

问题:

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.

回答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.



回答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.



回答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



回答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!



回答5:

I went to the cpanel>filemanager and edit the file wpconfig.php inside php tags i added if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';



回答6:

Go to phpadmin and find wp-options. Change siteurl and home to http. Its work :)