We have a lot of WordPress tutorials on learningcms where we had make use of .htaccess file for a specific reason and got a lot of queries about what is .htaccess file and how to find it? Most of our readers were even unable to find the file on their website hosting servers.

We have finally solved this mystery in this article answering all of these questions and adding a lot more information on .htaccess file.

What is .htaccess file?

.htaccess file is not a file specifically comes only with WordPress but it’s a server configuration file which can be used with any website.

Basically the file is used to define certain rules on per-directory basis using configuration directives. Separate .htaccess file can be used in a sub-directory to define rules only applied to that sub-directory.

Using .htaccess file on your blog you can set URL redirects, permalinks, blocking IP-addresses for security reasons, protecting admin page and directories.

Each task will add a block of code in .htaccess file called configuration directive.

Woopoo's Tip

WordPress plugins also use .htaccess file to define and set their own rules in the file. Not all plugins use this file but just as a hint, you will definitely see changes in .htaccess file once you install cache or security plugins.

Where is .htaccess file located?

.htaccess file location is the root directory of your WordPress website or blog mostly www or public_html folder. The path most likely will be /home/learningcms/public_html where learningcms will be your username instead.

One important thing to note is .htaccess file always starts with a dot and dot files in server settings are hidden files. You can’t see hidden files unless or until you unhide them and this what we are going to do in the next section.

How to find .htaccess file in CPanel ?

The first option to locate .htaccess file is through CPanel.

  • Login to your website CPanel and access public_html or root directory where you have installed WordPress.
  • Look for .htaccess file. If it’s not there it means .htaccess file is hidden and we have to unhide it.
  • Click the Settings button on the top right corner.
  • From the window that appears, enable Show Hidden Files and Save the settings.

cpanel show hidden files

  • The file will appear in your root directory. Here is how .htaccess file looks like in WordPress:

wordpress htaccess file

How to find .htaccess file with FTP account ?

If in case you are not able to login to your CPanel for some reason, you can do the same using an FTP account.

You must have an FTP account already setup in order to access the file.

Woopoo's Caution

See our article how to setup an FTP account for your website for more details.

1. Login to your ftp account.

2. Show hidden file settings depends upon the FTP software you are using. Generally you will find it in software preferences. For example, in WinSCP FTP software, you will find the settings in Preferences > Panels > Show hidden files.

ftp show hidden files

Look for the same option if you are using FileZilla or any other software.

Still can’t find .htaccess file ?

If you still can’t find it in the root directory then chances are your website is missing .htaccess file. There is no default .htaccess file comes with WordPress so either we have to create it manually or through WordPress settings. We will see both in the next section.

How to create .htaccess file ?

The recommended way to create an .htaccess file is through WordPress permalink settings. WordPress automatically creates an .htaccess file whenever you will switch from Plain permalink to a pretty permalink from your WordPress dashboard permalink settings. Pressing Save Changes will create the file.

wordpress permalink settings

Keep in mind changing permalinks will update your site URLs and any internal links will need to be updated manually according to new permalink settings.

The other way around is to add .htaccess file to WordPress manually.

  • Create a text file on your desktop and add the code whatever you want. If you try to name it .htaccess, you will get an error on Windows “You must type a file name“.

windows filename error

Make sure you are not saving .htaccess.txt which is wrong.

  • The solution is to open the file and from the main menu File > Save As… write .htaccess in inverted commas same as “.htaccess”
  • Now save the file.
  • Upload .htaccess file to root directory of your website either from CPanel or FTP.

Yet another way is to create .htaccess file in CPanel directly. Why not? let’s do it in two easy steps.

  • Go to your website root directory (www or public_html).
  • On the top left corner, click New File button.

cpanel create new file

  • Write .htaccess in file name and press Create New File.

How to edit .htaccess file in WordPress ?

Take extra care while editing .htaccess file in WordPress as it can make your site stops working. To edit or add code to .htaccess file:

  • In CPanel, right click the file and from the menu, click Edit to view the file in code/text editor and add your code.
  • You can also download the file from CPanel or using FTP for editing. Make your changes and upload it back to root directory.
  • If you get any errors related to overwriting is not allowed. Upload the file as .htaccess-new. Delete old .htaccess and rename the new one.

we have just arrived at the end of our tutorial. We hope you feel comfortable using .htaccess file on your WordPress site as we have tried our best to cover everything related.

If you still have any questions do let us know using the comments section below and don’t forget to follow us on Twitter or Facebook.

Gimme a Share pleeeaase!

Pin It on Pinterest

Share This