pda-edit-wordpress-default-htaccess

WordPress Default .htaccess: What is It and How to Create?

WordPress gives you the power to create and run your site without having to touch a piece of code or modify files and folders. All you need to do is set up a domain, choose a hosting provider, install WordPress, pick a theme, and customize the site.

Still, having some knowledge about WordPress core files and folders is advantageous for you to troubleshoot problems or make adjustments to the website. When WordPress is ready on your hosting, you’ll see a list of directories such as wp-admin, wp-content, and wp-includes.

One of the most important core directories is the WordPress default .htaccess file, which is used to basically control your website permalinks. You can also configure the file to customize many actions on your site.

In this article, we’ll show you where the .htaccess file is located and how to create it if you don’t have one for your WordPress site.

But first, let us quickly define the .htaccess file.

What is the .htaccess File?

Supported by Apache hosting and a few other web servers, .htaccess locates on your WordPress root directory. This default file is greatly critical to managing redirects and permalink structures.

Numerous WordPress plugins, especially security and caching plugins, also make use of .htaccess to enable their features. They add some code snippets to the file to carry out certain tasks. Creating 301 redirects, controlling SSL connections, password protecting directories, preventing hotlinking, and restricting site access, just to name a few.

How to Locate Default WordPress .htaccess File

After you install your WordPress site on an Apache hosting account, the .htaccess file is automatically added to the root directory. The dot at the beginning of the filename specifies that it’s hidden from the public view.

To locate the .htaccess file, log in to your cPanel account and then,

  1. Go to File Manager under the FILES section
    pda-file-manager-folder
  2. Click on the public_html directory in the left-hand navigation menu
    wp-content-folder-ftp
  3. Open the folder named “wordpress” and find your .htaccess file
  4. In case you don’t see the .htaccess file, go to Settings in the top-left corner
  5.  Tick on the Show Hidden Files box in the Preferences window

The WordPress default .htaccess file should show up now. There may be times you can’t find the file, so simply create one for your site.

How to Create a .htaccess File

There are 2 main reasons for no .htaccess files appearing in the root directory. It may happen that your WordPress installation doesn’t come with a .htaccess by default. An activated plugin can cause corruption in your server configuration and delete files as well.

WordPress allows you to generate a .htaccess file right from the admin dashboard, via the Permalinks feature.

  1. Log into your admin area
  2. Head to SettingsPermalinks
    pda-wordpress-settings-permalinks
  3. Scroll down and hit Save Changes

As a result, WordPress will automatically build a .htaccess file. If it fails to create one, you’ll see an error message saying “.htaccess file is not writeable.”

Now, you have to seek help from cPanel. The process is similar to what you’ve done to look for the .htaccess file.

  1. Visit File Manager after logging in to your cPanel’s hosting account
    pda-file-manager-folder
  2. Choose the public_html folder from the left-hand side menu
  3. Click on the +File icon at the top of the screen
    pda-plus-file-icon
  4. Provide the filename in the input field. It should be “.htaccess”
  5. Hit Create New File
  6. Edit the new file by right-clicking it and inserting the following code
# 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

Save your changes and close the file.

Edit Your WordPress .htaccess File

Adjusting the WordPress default .htaccess means you’re risking your site. Even a tiny improper edit on the file can affect the whole site’s performance.

To minimize the negative result, you need to back up your site or use a staging site. The backup allows you to restore the previous version if there is anything wrong happens to your site. On the other hand, the staging site gives you the environment to test changes.

We also recommend creating a backup .htaccess instead of directly editing the file on the server to avoid issues.

You can either edit .htaccess manually or use a plugin, depending on your technical skills.

Use cPanel

Similar to what you’ve done in locating and creating the .htaccess file above, this method requires you to log in to your cPanel’s hosting account. Once logging in,

  1. Open File Manager and you will see a menu on your left-hand side
  2. Click on the public_html folder
  3. Choose the wordpress folder under it and look for the .htaccess file
  4. Right-click to edit the file and add your desired code

Use Htaccess File Editor Plugin

If you’re not familiar with coding but want to ensure everything related to your .htaccess, opt for a reliable plugin in this case. Loved by over 60K users from pole to pole, Htaccess File Editor turns out to be the most popular plugin to edit your .htaccess file.

The plugin greatly assists you in editing, fixing, and testing the site’s .htaccess file right from your WordPress admin area. On top of that, it automatically creates a .htaccess backup when you take an action on the .htaccess file.

To get started with the plugin, follow the guide below:

  1. Install and activate the plugin by going to PluginsAdd New and type the plugin name in the keyword box
  2. Head over to WP Htaccess Editor under Settings on your WordPress navigation menu
    pda-wordpress-htaccess-editor
  3. Hit Enter to add a new line before # BEGIN WordPress
  4. Provide your code snippets to apply new rules to the .htaccess file

That’s it!

Make Use of WordPress Default .htaccess

.htaccess is always a vital configuration for every WordPress site running on the Apache web server. It defines your site functions correctly and makes your site accessible.

You can view and modify the .htaccess file via your hosting cPanel. We’ve shown you the method to locate the WordPress default .htaccess as well as how to create one if it’s unavailable.

It’s possible for you to make changes to the .htaccess file to perform various tasks such as IP blacklisting, directions, and password protection. To achieve that, you can manually edit your .htaccess or use the Htaccess File Editor plugin.

If you still have any other questions about WordPress .htaccess, let us know in the comment section below.