Table of contents
Get the industry’s fastest WordPress hosting◦ 99.999% uptime
◦ Comprehensive security
◦ 24/7 support

WordPress GuideDevelopment → Htaccess

WordPress basics: The Htaccess file

Image

Many new site owners find themselves asking a common question: where is the .htaccess file in WordPress sites? Before we get there, let’s zoom out to give some context. 

WordPress relies on several open-source applications, including the PHP interpreter, the MySQL database, and the Apache web server. Apache’s role is to pass requests to WordPress so that HTML pages can be generated. Apache then sends those pages to the browser that requested them. Without Apache, WordPress wouldn’t be on the web.

Apache can be configured to handle requests according to the needs of the application and its users. Most of that configuration lives in the httpd.conf file which acts as a centralized configuration file for all sites on the server. However, it is often necessary to customize the configuration for individual sites. This is where the WordPress .htaccess file comes in.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

Htaccess basics

The .htaccess file is among WordPress’s core files, and tells the server how to address certain aspects of your website such as redirecting users and protecting certain directories. It’s a server configuration file that allows and disallows certain functionality. Unlike the httpd.conf file, the .htaccess file is a per-directory configuration file that only affects the site in the same directory as the file. 

Most WordPress configurations can be done from within the WordPress admin dashboard, but in some cases, it can be useful to make changes to .htaccess. 

Before we look at how to find and edit the .htaccess file, it’s important to understand that mistakes in .htaccess can take a WordPress site offline, make pages inaccessible, or hurt its SEO. Be careful when editing .htaccess, and always have your site backed up.

Where is the Htaccess file in WordPress?

So, how do you locate the .htaccess file? If you look in your WordPress site’s root directory, you may find that it already has an .htaccess file. If it isn’t in your root directory, your .htaccess file may just be hidden from view by your File Transfer Protocol (FTP) client, as it’s a sensitive file that isn’t intended to be edited often. Another possibility, if you can’t find your .htaccess file, is that it just may not exist yet, but let’s back up and take a step-by-step look at how to find the .htaccess file. Generally, you can use the steps below, but keep in mind that there may be some differences with each hosting provider and FTP client.

If your .htaccess file is not appearing in the root folder, check with your FTP client on how to access hidden files as every FTP client has its own process.

How the Htaccess file works with WordPress

Whether or not you choose to manually edit the .htaccess file, it’s still being worked on by WordPress. WordPress adds rules to .htaccess, as do some WordPress plug-ins. When you change the permalink structure of a WordPress site, rules are written to the .htaccess file so that Apache knows about the changes. Security plug-ins often use .htaccess to block IP addresses or limit access to the site.

If you aren’t familiar with .htaccess or editing configuration files on the htaccess command line, you may prefer to find a plug-in that does what you need before attempting to manually edit .htaccess. These plug-ins are written by developers and extensively tested. 

But if you feel confident enough and have backed up your site, you can still gain quite a few benefits from changing your .htaccess file. From redirects to basic .htaccess security adjustments, let’s take a look at a few short and useful rules you can add on your own.

Create 301 redirects

A 301 redirect is used when a page is permanently moved to a new location. It lets browsers and search engines know that the page is located at a different URL. To redirect a page in your .htaccess file, add the following rule:

Block access to sensitive files

Many files in the WordPress directory shouldn’t be readable by the whole internet – the wp-php.config file is a good example. With the following rules, you can block access to files that should not be accessible to all browsers.

Keeping your sensitive files private with this basic .htaccess adjustment is a smart move, even for new site owners.

Prevent specific IP addresses from loading the site

The .htaccess file can also be used to deny access to requests from particular IPs.

This can be useful for blocking a small number of IP addresses by adding the rules below. 

However, if you’re having problems with brute force attacks against your WordPress site, a plug-in like SiteGuard WP is a more efficient solution.

Make sure to replace the IP address in the above with the address that you would like to block.

Stop directory browsing

Directory browsing, which is permitted by default, allows bad actors to see the files in your WordPress site’s directory – information that might be useful to them.

The above command will prevent directory browsing.

We’ve covered only a few of the many configuration options that can be used to control Apache. For a full explanation, take a look at .htaccess Guide.

Getting started with Htaccess files

We set out to answer a few important questions for WordPress site owners: Where is the .htaccess file in WordPress sites? What is it? And how do we make changes to .htaccess?

Ready to take the training wheels off your WordPress site? Upgrade to professional hosting and see how better speeds, security, and reliability provide a foundation for a website and a brand that people find engaging and trustworthy. Liquid Web’s WordPress hosting options configure business-class servers and support plans specifically for WordPress websites. 

Click through below to explore all of our WordPress hosting options, or chat with a WordPress expert right now to get answers and advice. 

Ready to get started?

Get the fastest, most secure WordPress.org hosting on the market.

Trust us to help you choose the ideal hosting solution

Loading form…