How to Restore a Damaged .htaccess File on a WordPress Site

Anyone who has maintained a WordPress blog for a significant length of time knows how it feels when their site is suddenly rendered inaccessible. Especially if you’re not a very savvy developer, it can really shake you up. Most of us are not in the habit of backing up our site every time we install or uninstall a plug-in. If you’re actively changing things it can be a major pain to backup before making any changes. But sometimes this costs us. Whether you’re working directly with the WordPress files, or a plug-in makes some erroneous changes your .htaccess file, sooner or later your installation will be unavailable. This is not an uncommon phenomena. What you need is to know how to get it back up as soon as possible with minimum downtime.

The redirect functionality in the .htaccess file in the root of your hosted web folder is critical to ensure WordPress works properly. If for any reason it gets corrupted, you can end up staring at “500” server errors. Or sometimes you’re unable to access your posts but have access to the admin area. Here are two ways to restore your damaged .htaccess file in either case.

Resetting Permalinks

Ideally you want to mess around with code as little as possible. If WordPress is somehow able to fix the .htaccess problems all on its own, that would be best. One of the ways to force WordPress to rewrite the .htaccess file is by resetting the permalinks structure. Here’s how you go about it.

In the WordPress dashboard go to “Settings”, and then “Permalinks”. Most blog owners would have created a special, link structure that reflects the organization of their site. The good news is that whenever you make a change on this page, WordPress rewrites the .htaccess find and “resets” it. So just select another option and hit “Save Changes”. Once the page refreshes, switch back to your preferred solution and save it again. Here’s the Permalink option on the side of the admin bar:

Permalinks setup

With a little bit of luck, this would have restored your .htaccess file and rendered your blog usable again. I have personally used this solution on many occasions when some plug-in makes an unexpected change.

What if your entire admin page is itself inaccessible? How do you restore the .htaccess file without logging in to WordPress at all?

Creating .htaccess using FTP

For this, you need access to your hosting directory either using the inbuilt file manager that your web host most likely provides you with, or using FTP. If you browse the with Firefox, you should make use of the awesome FireFTP add-on. Even though I’ve switched exclusively to Chrome, I install Firefox just to make use of this one plug in!

Create a new file in Notepad (if you’re using Windows) and rename it as “.htaccess”. Note that you may need to enable the option to show hidden files in order to see it after it has been created. This is because any files starting with a “.” is treated as a hidden file. Open it up and paste the following into it:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
2016-11-25T14:50:36+00:00 julio 11th, 2016|How To..., Tutorial, Wordpress|

Leave A Comment


Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información. ACEPTAR

Aviso de cookies