Internal Server Error in WordPress my blog fixed

I got this problem and it was there all the time. I tried to follow what was written in so called helpful web pages, but what they suggested did not work. Finally I had to debug the code myself. I got it fixed and the fix below is quite simple for you to try. Save wp-login.php first in order to recover it in case you have fat fingers and tend to destroy source files.

Go with ftp to the files and locate wp-login.php. It is in the root. You can edit it with the WinSCP editor, or if you use some other ftp, copy the file to you, edit it with some suitable editor (like emacs) and copy back to the server. Locate the following place from wp-login.php. It is around line 920. You can see that there is a redirect. That is what fails. See what I wrote to the end of the if-sentence. Read my comments.

 

*************** FIND THIS CODE ************************

if ( ( empty( $redirect_to ) || $redirect_to == ‘wp-admin/’ || $redirect_to == admin_url() ) ) {

// If the user doesn’t belong to a blog, send them to user admin. If the user can’t edit posts, send them to their profile.

if ( is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin( $user->ID ) )

$redirect_to = user_admin_url();

elseif ( is_multisite() && !$user->has_cap(‘read’) )

$redirect_to = get_dashboard_url( $user->ID );

elseif ( !$user->has_cap(‘edit_posts’) )

$redirect_to = $user->has_cap( ‘read’ ) ? admin_url( ‘profile.php’ ) : home_url();

 

/** MY FIX IS HERE copy this stuff changing my url to your url  */

else { /** Jorma’s fix Feb 2018 around line 920 in wp-login.php        */

/** the case of the if above is that $redirect_to==admin_url()  */

/** you can do printf($redirect_to); just to verify it          */

/** but remove it, printf here makes error in pluggable.php  */

/** the code tries to do the following and gets Internal Server Error */

/** wp_redirect(‘http://www.pienisalaliittotutkimus.com/wp-admin/’);  */

/** it is also not OK to call the index.php in the root directory     */

/** wp_redirect(‘http://www.pienisalaliittotutkimus.com/index.php’);  */

/** it logs you in but does not work. You must do the following       */

wp_redirect(‘http://www.pienisalaliittotutkimus.com/wp-admin/index.php’);

exit();

/** so it is simply that the url must include index.php and it does not  */

/** these comments you of course do not need to copy,  just helpful   */

}

/** END MY FIX end copy */

wp_redirect( $redirect_to );

exit();

}

Good luck, hope it works. It looks like an error in wp-login.php. The url should include index.php. It is rather easy to debug php of wordpress. php has the prinf command, but use it just to track where the execution goes as adding printfs causes pluggable.php to complain. Locate where the problem is by putting enough printfs and taking them off. Then when you found the problem line, see what is wrong. printf prints a string fine. Notice that if you are inside javascript then printf will not work, and in any case, these are scripting languages, do not expect them to work all the time.

So, what you do if you get this Internal Server Error, is that forget those helpful web-pages, except for mine, because I say correctly. You better debug the login code rather than try in random all kind of things. If you do not have a ftp, download WinSCP for free. It has an editor and all you need. Login goes through the script wp-login.php and you only need to debug this small file. Notice that login goes two times through this script. First time it draws the login box to the screen. You can add printf(“hello”); to the very end of the wp-login.php file and notice that this text is printed on the screen. (In the end the printf does not do anything bad). Then you give the username and password and execution runs another time through the script. It is supposed to go again to switch case login, if you try to login. There it is supposed to go the redirect, the code I have above. So, this is the generic debugging method of an old professional. No need to know the programming language. Put printfs, or other things that do something that you can notice, just to see where the execution goes. Then locate the exact place where it fails and think and find out what the data is there. When you got the line where it fails, put it into google and you get other similar code pieces and can figure out what it does and how it should be. It is all very simple and straightforward. This is no rocket science (though rocket science is not any more difficult).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.