How to Create and Edit WordPress htaccess File

Updated on

WordPress htaccess File is an important system file, it can be found in your websiteโ€™s root directory. In this article,ย I will share how you can Create and Edit WordPress htaccess File. How htaccess file works? and How you can optimize your website by using the htaccess file?

In addition to that, I will also discuss, why you should use htaccess file to improve your site performance?

You might know that you can Create WordPress htaccess file manually via cPanel. But did you know that you edit your htaccess file directly from your WordPress dashboard?

You can Edit WordPress htaccess file using the most popular SEO plugin on WordPress repository. Yes! you guessed it right! Yoast SEO plugin. I will also discuss the different ways to access a htaccess file in WordPressย using a FTP client FileZilla.

WordPress is a much versatile platform and it also comes with very advanced features. You can control almost each and every activity and behavior of your website via WordPress dashboard.

One of the most utilized features in WordPress is to access the htaccess file directly from your WordPress dashboard. ย Simply you can understand that you have the liberty to access and edit root folders from Dashboard of your website if you are using WordPress.

How to Create and Edit WordPress htaccess File
How to Create and Edit WordPress htaccess File

Why use htaccess File to Improve Site Performance?

The htaccess file is an important system file of your website. You can use htaccess to enable or disable safety features, can change the behavior of handling search engine bots.

One can also add write/rewrite rules for URL redirections. It is also helpful to build a safeguard for your website against spammers.

Most of all bloggers use htaccess file to activate DEFLATE and Gzip compression. You can add expire headers or change the ‘Etag’ functions to Leverage Browser Caching and much more.

WordPress .htaccess file can be edited by using plugins or by direct access to your server File Manager.

First of all, I will walk you through about the use and functionality of WordPress .htaccess file and after that will share how you can create it and edit the same.

What is a htaccess file?

The .htaccess file belongs to your Apache server. Basically, it is a server configuration file which communicates with the server to behave for your website as per the rules and instructions are given in the htaccess file. According to WordPress

The .htaccess is a distributed configuration file and is how Apache handles configuration changes on a per-directory basis. WordPress uses this file to manipulate how Apache serves files from its root directory and subdirectories thereof. Most notably, WP modifies this file to be able to handle pretty permalinks.

Furthermore, htaccess file name has a dot (.) at the beginning, which specifies that it is a hidden file. You have to Turn On โ€˜show hidden file featureโ€™ when you are trying to access your .htaccess file using FTP client or cPanel of your hosting.

Since we have learned about the WordPress .htaccess file, how it works and why we should use it. Now let’s discuss how you can Create WordPress htaccess file.

How to Create WordPress htaccess file?

In most of the cases, WordPress creates the htaccess file automatically, when the first time you choose your Permalink Structure.ย Learn about the Most SEO friendly Permalink Structure for WordPress Blog.

However, there are few cases when WordPress might not generate htaccess file automatically because of some file read/write/create permissions at your server end.

Select WordPress Permalinks Structure and it will Create WordPress htaccess file automatically
Select WordPress Permalinks Structure and it will Create WordPress htaccess file automatically

Here I am sharing few steps to Create WordPress htaccess file manually.

  • First of all, create a text file on your computer.
  • Copy and Paste the below-given code in that file.
  • Rename the file extension of your text file from .txt to .htaccess.
  • And upload your .htaccess file in your websites root directory by using your CPanelโ€™s File Manager.
  • Finally, You need to upload .htaccess file at this location …/home/yourweb/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

How to Edit WordPress htaccess file?

WordPress .htaccess file can be accessed and edited using multiple ways. Here, I am sharing Four majorly recommended methods to Edit WordPress htaccess file.

# Edit WordPress htaccess file using cPanel

  • First of all, login to your hosting account or directly log in to your cPanel.
  • Go to the file manager.
  • Head over to the settings and Turn On hidden file, if already not activated.
  • Find your websiteโ€™s root directory.
  • Look for the .htaccess file in the public_html folder or in your websites root directory.
  • FInally, right-click on the .htaccess file and follow your cPanel instructions to edit the file.

# Edit WordPress htaccess file using Yoast SEO Plugin

  1. We all use SEO plugins in WordPress and most commonly used SEO plugin is WordPress SEO by Yoast.
  2. This plugin has a feature to access and edit .htaccess file.
  3. Another plugin on the list is WP Htaccess Editor, You can use this separate plugin to edit .htaccess file.
Edit WordPress htaccess file using Yoast SEO Plugin

First, I recommend you to not use a separate plugin to Edit WordPress htaccess file. and secondly always take a backup before Editing htaccess file.

Hope you find this information about Create and Edit WordPress htaccess File useful. Share which method do you use for the same via the comment section below.

Do share this post with your friends and acquaintances. Feel free to ask if you stuck somewhere while applying these methods on your website.

Cheers!

In addition to that, you may be interested to read following tutorials โ€“
How to Optimize WordPress Robots.txt file for SEO
Disable Server Signature by Editing .htaccess/Apache
SEO Keyword Research Tips and Tricks for Bloggers
Top Search Ranking Factors to Improve SEO of Your Website

Photo of author
Saurabh K
Saurabh K is a technology enthusiast and part-time blogger. He loves to explore the efficient use of technology and gadgets. He is an outlier and lensman. Add him in your social circle to know more.
Disclaimer: Affiliate links of some product(s) are being used on this page, if you follow the link and make a purchase, we may receive compensation from respective companies. This compensation comes at no additional cost to you.

23 thoughts on “How to Create and Edit WordPress htaccess File”

  1. Avatar of varun dhaketa

    i have a problem to find .htaccess file in wordpress.ca you help me

    Reply
    • Avatar of Saurabh K

      Hey Varun,
      Let me know your issue, I’ll be happy to help.
      Thanks for your response.

      Reply
  2. Avatar of Sasto Nepal

    Thank for sharing tutorial base ideas to create and edit wordpress htaccess file. It worked for me and would like to recommend this ideas to all.

    Reply
    • Hey,
      Glad that you liked it.
      Thanks for your feedback.

      Reply
  3. Avatar of Swapnil

    With the help of above tutorial just created .htaccess file and resolving issue of Leverage Browser Caching. Thank you so much:)

    Reply
    • Hey Swapnil,
      Glad that I could help.
      Thanks for stopping by.

      Reply
  4. Avatar of Max

    Thanks for sharing.. been searching for this since moring

    Reply
  5. Avatar of ariasungroup.ir

    nice article,thanks.

    Reply
  6. Avatar of itroz

    Thanks for awesome article

    Reply
    • Avatar of Marcus Djones

      hi Saurabh,
      can you guide me under what circumstances I will have to edit .htaccess file?? I mean how will I come to know that my site requires edit in the .htaccess file…
      looking fwd to your help…thanks

      Reply
      • Hi Marcus Djones,
        There is no specific reason to edit htaccess file. However, if you want to add some functionality or wanted to improve your site performance. Editing htaccess is one of the most recommended way to achieve your goal.

        Reply
  7. Avatar of Franklin Obioha

    Thanks

    Reply
  8. Avatar of SeeSite

    Thanks for your tutorial. It saved a lot of my time ๐Ÿ˜‰

    Reply
  9. Avatar of Manish Lamba

    Thank You for this beautiful article.it will help to understand WordPress more easily.

    Reply
  10. Avatar of Andrea

    THANK you. This brought my Google score up from an F to a B.

    Reply
    • Glad! I could’ve helped. Thanks for stopping by.

      Reply
  11. Avatar of Lanette

    This information about htaccess would have saved us a lot of effort early on.

    Reply
  12. Avatar of Kuahal Jain

    How to access root directory of my website? Urgent!!!!!
    And your posts are awesome.

    Reply
    • Avatar of Saurabh K

      Use the File Manager on cPanel to access the root directory of your website. Otherwise, you can access it using your FTP account with FileZilla.

      Reply
  13. Avatar of suresh pawar

    It is truly a nice and useful piece of info. I am glad that you just
    shared this useful information with us. Please stay
    us up to date like this. Thanks for sharing.

    Reply
  14. Avatar of Haris Akram

    Great article it is very helpful. Nicely explained.

    Reply
  15. Avatar of Sagar Chauhan

    With the help of above tutorial just created .htaccess file and resolving issue of Leverage Browser Caching. Thank you for sharing bro ๐Ÿ™‚

    Reply
    • Avatar of Saurabh K

      Glad, I could help. Thank you for stopping by.

      Reply

Leave a Comment

Your email address and website details will not be published. Required fields are marked with *.