Yesterday as I sat down to work, I took the time to update some plugins on my site. Based on my golden rule, I always wait until an updated plugin has been out for at least 4 days before applying the patch. This allows time for the developer to become aware of any new bugs, and I don’t want to be impacted by improper testing. Nonetheless, despite my best precautions, my site broke and I got a 500 server error.
There’s something very debilitating about a 500 error. It gives no useful information and doesn’t point you in any direction. And despite years and years of hosting my own site, I still feel a lump of fear whenever I see that error page. But once I’ve forced that down, I start to examine what went wrong. And it’s almost always a broken .htaccess file.
Confirming .htaccess Problems
When I’m confronted with a 500 error, the first thing I do is to go into cPanel and search the error longs. With NameHero, you can find it under the “Metrics” section like this:
Any server errors caused due to an .htaccess misconfiguration will be highlighted here. And hopefully, it’ll give you a helpful debugging message as well. In my case yesterday, the error log confirmed an .htaccess problem. So clearly, the update had broken something. But what?
Finding the .htaccess Error with htaccesscheck.com
I run WordPress on my site, and by default the blank .htaccess rules are pretty small. But almost no one runs a site without any plugins, and the typical .htaccess is probably going to be quite large, consisting of rules from security plugins, caching plugins, various directives regarding expiration times, and more.
So finding the error in a large .htaccess file is anything but trivial. Luckily, we have a good tool at our disposal – namely htaccesscheck.com. On the homepage, you simply need to paste the file into the textarea, or upload your existing file as shown here:
Click the submit button, and the page will reload giving you a summary of the error in the .htaccess file as shown here:
In the screenshot, you can see that the script identifies problems in lines 292 and 297. Since the entire file is presented below with line numbers, it’s easy to scroll down and find them. In this case, this is what I see:
At a glance, you can immediately see the problem. .htaccess files are parsed on a line by line basis. In this example, whichever script modified the file during the plugin update, forgot to insert a new line after the last </IfModule> statement. This results in a syntax error since there’s no space between the start of the comment.
So the fix is simple. Simply give the # BEGIN WordPress comment a new line on its own, and the .htaccess error vanishes.
Breaks During Updates Are Typically Easy to Fix
Luckily, most 500 errors that occur after a site breaks, are easy to fix. The reason is that it’s probably not due to some underlying logic error, but a syntax error of the kind seen above. So while 500 errors are scary, they shouldn’t be too hard to fix provided you use the right tools to identify them.
Use the htaccesscheck.com site to verify your .htaccess file for syntax errors. Hopefully, this will make it a bit easier for you to fix errors that occur when you update your site, and give you a bit more confidence in your ability to fix your own problems without needing someone else to do it for you.
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!