WordPress .htaccess: how to find and create the default file
In this article, we’ll show you how to find and create the WordPress .htaccess file.
When you install WordPress on your hosting account, the software adds a set of folders to your server. These range from wp-admin, which stores administrative files, to the wp-content directory, which holds themes and plugins. These directories are what keep your site’s pages online.
Along with the main folders, WordPress also includes the .htaccess file. In short, it’s a configuration file that controls how your server runs. Only some types of servers support it, including Apache.
Contents
How to find the .htaccess file in WordPress
How to create the WordPress .htaccess file using the recommended default
Prerequisites
To begin, you’ll need your domain/website already set up in MigraCloud’s infrastructure.
- Access to the cPanel control panel
What is .htaccess
.htaccess (hypertext access) is an essential WordPress file used to enable or disable features on sites hosted on Apache. .htaccess files are also called server configuration files, and they’re located in the root directory of your WordPress installation. By default, WordPress uses .htaccess to manage redirects and permalink structures.
Many WordPress plugins also use .htaccess files to work, including most security and caching plugins. They modify and rewrite .htaccess to carry out their functions.
The .htaccess file lets you make configuration changes for each directory, from changing your default index page to changing the time zone.
How to find the .htaccess file in WordPress
When you install WordPress on Apache Web Server, the .htaccess file is automatically added to your root directory, public_html. However, this file is usually hidden, so you need to use the Show Hidden Files option to find it.
1 – Log in to your cPanel account. Find the Files section and click File Manager
2 – Open the public_html directory and look for the .htaccess file in the folder where WordPress is installed.
3 – If you can’t find the .htaccess file, go to Settings in the upper-right menu and check Show Hidden Files.
4 – The system will start loading your directory contents, and you’ll soon see the .htaccess file in the list.
How to create the WordPress .htaccess file using the recommended default.
If you use cPanel, click the File button in the upper-left corner of your screen.
Type .htaccess as the file name, then enter the code below:
This is the default WordPress .htaccess file (provided by WordPress itself)
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Once you’ve added this code, click Create to save your changes. Keep in mind that this snippet is standard for all WordPress sites. Other content management systems (CMSs), however, will have different code for their .htaccess files.
As an alternative, you can use a text editor such as Notepad to create a .htaccess file, then upload it to your server using an FTP client.
Conclusion
The .htaccess file is a configuration document used on sites that run on Apache and LiteSpeed servers.
This file plays an important role in keeping your site accessible to users. It determines how the server runs and how it operates.
Every WordPress installation includes a default .htaccess file, which you can access through your hosting control panel or an FTP client.
In this guide, you learned how to find the .htaccess files on your server.
If for some reason they aren’t there, you’ll have to create the file manually and upload it to the server.
Simply create a new file in the public_html directory, name it .htaccess, and fill it with the default code.