Thursday, December 1, 2022
HomeTutorialHow Create and Locate the WordPress .htaccess File

How Create and Locate the WordPress .htaccess File

When you install WordPress on your hosting account, the software adds a list of directories to your web server. From wp-admin that stores administrative files to the wp-content directory where themes and plugins are kept – these keep your pages up and running.

WordPress also comes with a .htaccess file in addition to the core directories. In short, it is a configuration file that controls how your server is running. Only a few web servers, including Apache, support the file.

For those of you who host a website on an Apache Web server and would like to use the .htaccess file, this article is for you. You will learn where to find this configuration file as well as how to create a new file from scratch.

.htaccess File – What Is It?

WordPress Default .htaccess File
WordPress Default .htaccess File

Hypertext Access (.htaccess) is a core WordPress file that is used to enable or disable features on websites hosted on Apache. The .htaccess files are also known as server configuration files. They are located in the root directory of your WordPress installation. WordPress manages redirects and permalink structures through .htaccess files by default.

The majority of WordPress security plugins and caching plugins also use .htaccess files. These plugins modify and rewrite the .htaccess files to perform their functions.

The .htaccess file allows you to perform configuration changes per-directory basis, from altering your default index page to changing your website’s time zone. More advanced server configuration changes include the ability to:

  • Set up redirects – either a 302 redirect to your temporary domain or a 301 redirect to move all HTTP traffic to your HTTPS site.

  • Rewrite URL – improve crawlability and indexability by creating SEO-friendly URLs.

  • Enable hotlink protection – you can protect your bandwidth by using the .htaccess file.

  • Modify access restriction – block specific IP addresses, make a certain type of file inaccessible, or completely restrict access.

  • Serve custom error pages – customize 404 error pages.

  • Password-protect directories – Create a .htpasswd file and set up a password for every directory.

You can use this free .htaccess generator to create code snippets and set up more advanced rules.

Where to find WordPress .htaccess

Apache Web Server adds the .htaccess file to the root directory, usually public_html or www, when you install WordPress. You will need to use the Show Hidden Files option to find the file since it is usually hidden.

The following sections will walk you through the steps of locating your WordPress site’s .

Similar steps are required if you use cPanel:

  1. Access your cPanel account. Click File Manager in the Files section.

cpanel-file-manager

2. Go to the public_html directory. Go to your WordPress Installation folder.

3. To view the .htaccess file, go to the Settings menu on the upper right and select Show Hidden Files.

cPanel show hidden files How Create and Locate the WordPress .htaccess File

4. As soon as your directories’ content is fetched, you will see the .htaccess file.

5. To open the file, click on it and check the Edit button.

You can now edit your .htaccess file. Add code snippets above or below the existing code to enhance your WordPress site’s functionality. There are several factors to consider before making any configurations:

  • Each domain in your hosting plan will have its own .htaccess file in its public_html directory.

  • Messing up the code in .htaccess can cause errors on the server.

  • Creating a backup is highly recommended. You can restore your WordPress site to its stable state whenever an error occurs.

Create a default WordPress .htaccess file

The .htaccess file may not be included by default in your WordPress installation. It is also possible for a broken plugin to corrupt this server configuration file. You will need to manually create a new file from your hosting control panel.

Choose the New File button in the upper-left corner of cPanel.

Insert the following code in the file .htaccess:

# 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

Press Create once you’ve added the code. You can use this code on any WordPress site. Other content management systems (CMS) will have different .htaccess files.

Additionally, you can use Notepad to create a .htaccess file, then upload it using an FTP client to your web server.

Conclusion

In websites running on Apache web server, the WordPress .htaccess file is used for configuration. It keeps your site accessible. A server’s functionality is determined by it.

Your hosting control panel or FTP client will include a .htaccess file with every WordPress installation. Your web server will have multiple .htaccess files if you host multiple sites.

You can configure your website on a per-directory basis using .htaccess files. It involves blacklisting or whitelisting specific IP addresses, redirecting traffic from HTTP to HTTPS, and setting up passwords.

You have learned how to locate your server’s .htaccess files. .htaccess files need to be manually created and uploaded to your server if they are not present. In the public_html directory, create a new file named .htaccess and fill out the default code.

If you have any questions, please leave them in the comments.

Ankit Bhandari
Ankit Bhandarihttps://www.bhandariankit.com
My mission is to empower people to take control of their health and fitness by following a healthy, enjoyable lifestyle that not only gives them the body they’ve always wanted, but enables them to live a long, vital, disease-free life.
RELATED ARTICLES

Leave a Reply

Most Popular

Recent Comments