3 easy steps to Create and Edit .htaccess File in WordPress

3 easy steps to Create and Edit .htaccess File in WordPress

In this post, we will look at how to Create and Edit .htaccess File in WordPress. How it works and How you can optimize your website via the htaccess file? You can also implement a number of changes on your site by editing htaccess. The changes contain; redirecting URLs, securing your images from hotlinking, preventing access to site folder or blocking IPs from accessing your site. But before this, you must know about the .htaccess file in WordPress so let’s have a brief look:-

What is a .htaccess file?

As we all know that .htaccess file belongs to Apache server. Actually, this is the server configuration file that communicates with the server to respond to your WordPress Website.

In addition, the .htaccess file name appears along with a dot (.) in its prefix. Thus, this states that this is a hidden file. However, when you are trying to use your .htaccess file using an FTP client or cPanel of your hosting, you must have to turn on the “Show hidden files feature.”

Since we have discussed the .htaccess file. And it’s little bit description. Now let’s move towards the Why do we use such files to Improve the Site Performance?

Why we use .htaccess File to Improve Site Performance?

The .htaccess file is a valuable system file of your site. However, you may use .htaccess to enable or disable security features. On the other hand, you may change the behavior of handling search engine bots.

Anyone can write/read rules for URL redirection, it is also useful for maintaining security for your WordPress site against spammers. Well, .htaccess file can be edited using the plugin or by the direct access to your server file manager.

Now, let’s move towards the creation of the .htaccess file. Which is illustrated as follows:

Precautions of Editing .htaccess

When you are editing .htaccess. However,  it’s important to exercise maximum caution since errors on .htaccess file will cause your site to crash. Finding .htaccess can also be difficult; Here are two precautions to guide while editing the .htaccess file:

  • Show Hidden Files -:- While editing .htaccess in cPanel. You will need to check the “Show hidden files” setting to view and edit .htaccess. However, in some web hosting, you may require changing the permission settings to view the same .htaccess file.
  • Backup .htaccess -:- Creating a backup copy of the .htaccess file while editing the same file is the most important precaution. However, this backup copy is used to restore back the website to the original status.

Creating .htaccess File in WordPress?

WordPress is a self-hosted blog. However, being so, you get the flexibility to play with root folders. Hence, today I am going to talk about WordPress .htaccess file for several reasons. You can set up several security settings using the Wp.htaccess file, add rules for redirection, block bots, secure your blog with spammers, and many more.

Well, WordPress creates the .htaccess file automatically. Somehow, there are few cases when WordPress might not generate .htaccess file automatically. Because of some file “read/write/create” permissions at your server end.

Thus, here I am illustrating few steps to do so manually. Which are as follows:

  • First, create a text file on your PC.
  • Copy and paste the given code into that file.
  • Rename the file extension of your text file from .txt to .htaccess.
  • And upload your .htaccess file to your website’s root directory. Using your CPanel file manager.
  • Finally, you need to upload the .htaccess file to this place. The path to upload the file is as follows: /home/your web/public_html/.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

Ways of Editing .htaccess File in WordPress

There are different ways that you can use to edit the .htaccess file, which includes:

  • Edit .htaccess file using cPanel.
  • Edit .htaccess file using FTP client – Filezilla.
  • Edit .htaccess file using Yoast SEO Plugin.

The fast way to edit the .htaccess file is via CPanel. Well, this article will explain each of these methods of editing.

1.  Edit .htaccess file using cPanel

  • First of all, login to your hosting account or login directly to your CPanel.
  • Move towards the file manager.
  • Go to settings and turn on hidden files, if till are not activated.
  • After that, find the root directory of your website.
  • Have a look at the .htaccess file. In the public_html folder or your website root directory.
  • At last, press right-clicks on the .htaccess file. And follow your cPanel instructions to edit the file from your PC.

2.  Edit .htaccess file using FTP client – Filezilla

Editing .htaccess files using FTP client. Requires you to the first login to your File Transfer Protocol client such as FileZilla. After that, FTP login can be obtained from your hosting cPanel, where you can also reset the password from your working PC.

You should navigate to the main menu on the server. And make sure that the “Force Showing Hidden Files” option is checked.

However, after locating the .htaccess file. Make download it and the other you need to do is. Make a backup copy too before you began editing it. If you are facing error to upload the file then see our article on How to Upload a File in WordPress using FTP

3.  Edit .htaccess file using Yoast SEO Plugin

  • We all use SEO plugins in WordPress. And the most used SEO plugin is WordPress SEO by Yoast. To know more see our article on How to Optimize Yoast SEO plugin in WordPress
  • However, this plugin has a feature. And the feature is to access and edit the .htaccess file.
  • Well, we are not bounded with this plugin. Another plugin in the list is the WP .htaccess Editor. You may use any of them with your wish.

The thing needs to be said are. Use a different plugin to edit the .htaccess file in WordPress. And before editing the .htaccess file make a backup of it.

CONCLUSION

Here, in this blog, we have discussed How to Create and Edit .htaccess File in WordPress?

Often we concluded its layout, its definition, why do we use it, precautions before editing the same, and the process of the very job. Performing this we came across the three methods which are as follows:

1: Edit .htaccess file using cPanel.

2: Edit .htaccess file using FTP client – Filezilla.

3: Edit .htaccess file using Yoast SEO Plugin.

They do add value to any blog post. And, this leads to the end of the blog.

We hope this blog helped you. However, if you found the blog useful, do not forget to use the comment section provided below. 

If you require any help regarding WordPress Website Maintenance then feel free to contact our Toll-Free number + 1 888 614 0555. We will be glad to help you.

Read More Blogs:



Leave a Reply