Create And Edit WordPress .htaccess File : WordPress being a self-hosted blogging platform is very versatile. You can control every single thing of your blog or website as WordPress allows users to access root folder. So today I am going to discuss a file named .htaccess which is present in the root folder of your WordPress site.
What Is WordPress .htaccess File ?
.htaccess is probably one of the most important and useful files. .htaccess is a server configuration file and communicates with your hosting server to tells how to handle certain things on your site.
With this, you can fully optimize your self-hosted WordPress website. You can do whole lots of things like security settings, block search engine bots, activate Gzip compression, add expire headers, security from spammers, add redirection rules, protecting directories and much more.
The dot before htaccess file indicates that this is a hidden file. To access this you just need to Turn on show hidden file feature when trying to access your .htaccess file through FTP client or cPanel. Now let's move on to the article and learn how to create this file in WordPress.
How To Create WordPress .htaccess File ?
WordPress automatically generates the .htaccess file for the first time when you set up permalink structure for your blog. You just need to go to Settings >> Permalinks and click on save changes there. Then WordPress will automatically generate a .htaccess file in your website root directory.
In rare cases, WordPress may not be able to generate .htaccess file automatically because of file permission issue. In this case, go to Settings >> Permalinks, here at the bottom WordPress will show you a notice informing that your .htaccess file is not writable.
If you have set your permalinks structure to other settings then default it will show you a code that you need to paste in your .htaccess file.
Copy the code and paste it into notepad and save it as .htaccess on your desktop. Now Upload this file to the public_html folder in root directory by connecting your WordPress site using an FTP client like Filezilla or using File Manager in cPanel. You can check the steps below with screenshots.
In case you are getting an error while uploading, then you need to change the file permission of your root directory.
You need to change your public_html permission. Just right click on the public_html folder and click on change permission, now a dialog box will appear. Now enter 755 into the numeric value field and click
Now you should be able to upload your file successfully. Make sure to change the permission back to 644.
How To Edit WordPress .htaccess file ?
You can access and edit WordPress .htaccess file in many ways. In this article, I will be sharing some really easy and quick ways to access and edit .htaccess in WordPress.
1. Edit .htaccess File In WordPress Using cPanel
Most of the best and reliable WordPress hosting providers offer cPanel to their customers. Using cPanel to access and edit .htaccess is very fast and easy method. Highly recommended for non-technical people.
Login to your cPanel account and under files section click on File Manager.
Now select the home directory and make sure to mark show hidden files.
Then open public_html folder select .htaccess file and click on Edit File. Now you can add codes in the edit and save the file.
2. Edit .htaccess File From WordPress Dashboard
Access and edit .htaccess file directly from WordPress dashboard using WordPress plugins. Many plugins are available like WP Htaccess Editor etc. If you are already using Yoast SEO WordPress plugin, then you can access it from SEO >> Tools >> File Editor.
If you are not using Yoast SEO plugins then I would recommend you to start using from this very moment. Also check out this guide to properly setup and configure Yoast SEO WordPress plugin.
3. Edit .htaccess File Using FTP Client
If you are looking for more control then you must follow this method. If you want to edit WordPress .htaccess on your desktop then this method id perfect for you. This is the method I love and use. You just need an FTP client like Filezilla and login to your FTP account. But make sure to turn show hidden file feature on under Server >> Force Showing Hidden Files.
Now browse to your website root directory and edit or download WordPress .htaccess file. And once you are done with the editing re-upload it back.
I would recommend you to take backup of your WordPress .htaccess
file before editing. As incorrect .htaccess file, it can greatly affect your website. And make sure to change file permission of WordPress .htaccess file to 644 for security.
I hope you find this information helpful. Do share it on Facebook and Google+ and do subscribe to our newsletter for free updates.