The WordPress .htaccess
The .htaccess in WordPress (short for Hypertext Access) is a file that configures how your server serves files in the directory. According to the WordPress Codex:
WordPress uses this file to manipulate how Apache serves files from its root directory, and subdirectories thereof.
The most common use of the .htaccess is for “Pretty” permalinks (http://yourdomain.com/your-post vs. http://yourdomain.com/?p=123). When you change your permalink settings in the WordPress dashboard, WordPress adds this to your .htaccess:
# 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] </IfModule> # END WordPress
The .htaccess is also used to strengthen your website’s security, ban IPs, handle redirects, and many other events that must be processed by your server.
How to Edit the WordPress .htaccess
When editing your site’s .htaccess, it is important to ALWAYS make a backup of the code before you add your edits. The .htaccess is a very sensitive file and a small typo can crash your entire website so creating a backup can help you get back up and running in less time. Also, make sure to test your site after you’ve saved your changes to verify that 1.) your website hasn’t crashed, and 2.) it’s functioning without any errors.
To edit the .htaccess file, I find it easiest to use the file manager client typically included with most hosting providers. The reason I prefer this over another client like FileZilla is because FileZilla can be tricky to use with “hidden”, or server, files. Using cPanel’s file manager, for example, allows you to easily find and make edits to server files. To edit a file using the cPanel editor, simply right-click on the file and click “Edit”.
Assuming you are using “Pretty” permalinks, the code above can be pasted into the .htaccess to return the file to its bare minimum. You can also delete all of the code and save the file completely blank (you’ll need to re-save your permalinks setting).
Wondering where .htaccess code snippets are pasted within the file?
Conclusion
Editing your WordPress website’s .htaccess can give your site some excellent features. When pasting in a .htaccess snippet, just remember to be careful and ALWAYS ALWAYS paste your already-working code somewhere safe so you can return it if something goes wrong.
Leave a Reply