Chat Zalo Chat Messenger Phone Number Đăng nhập
WordPress .htaccess File - Location, Create & Example

WordPress .htaccess File – Location, Create & Example

There is one file that controls various aspects of how your WordPress installation handles requests made, this is the .htaccess file. In this article, we will provide more information about it.

What

is the .htaccess file for WordPress

? The .htaccess file is a configuration file that the Apache HTTP server uses to manipulate how your site handles requests made to it. For example, let’s say your browser is a client asking questions and the server is the person answering those questions. The client gives the server a note full of questions and the server needs to return another note containing answers to the questions asked. Depending on the .htaccess file and other settings, the server will return a different response. Other configuration files are set by server administrators and are not available for editing by clients. The .htaccess file is how customers can manipulate how their sites behave, as they have direct access to it and its content.

Where

is the .htaccess file located in WordPress

? The primary .htaccess file is located at the document root of your domain. For cPanel parent domains, the document root is the public_html directory. You can take a look at our article on how to find your document root from here.

Notice how the .htaccess file has a .dot in front of it. This .dot makes the file part of the dot files on a Linux system, those files are usually hidden from normal users as they are configuration files. In a cPanel environment, you can see the .dot files that are hidden by default in your File Manager by checking the Settings ->Show hidden files (dot files) settings

You should then be able to see

the .htaccess file in the document root for the domain.

<img src="https://www.webhostface.com/kb/wp-content/uploads/2019/01/WordPress-.htaccess-File-Location.png" alt="The primary location of the .htaccess file for WordPress installations" /> WordPress

.htaccess file

Default content

The default WordPress .htaccess file contains the following instructions:

# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> #END WordPress

Notice how there are comments indicating where the default WordPress code starts and ends (#BEGIN, #END). Those are commonly used by plugins to add additional configuration options to your WordPress installation to instruct how the server should handle requests made to it.

The BEGIN and END are used to indicate where a plugin’s .htaccess code begins and ends. Some plugins may add their own rule for caching or security purposes and are usually marked in the following format

: # BEGIN plugin name rules // rules that are added by the plugin # END plugin name rules Create a WordPress .htaccess file If you find that your

.htaccess file

is not created, you can easily re-create it from your WordPress dashboard by navigating to:

WordPress Panel -> Settings ->

Permalinks -> Click Save without making any changes

The .htaccess file

must be generated with the correct default WordPress rules

.

If you want to re-create the .htaccess file via cPanel, you can also

:

cPanel -> File Manager -> Navigate to the root directory of your domain -> +File (top left) ->New file name:

.htaccess

<img src="https://www.webhostface.com/kb/wp-content/uploads/2019/01/cPanel-Create-.htaccess-File.png" alt="Create a

.htaccess file” />

Once the file is created, you can edit it and enter the default .htaccess rules listed above into the file.

<img

src=”https://www.webhostface.com/kb/wp-content/uploads/2019/01/cPanel-Edit-.htaccess.png” alt=”Editing an .htaccess file in cPanel” />

Saving changes to an .htaccess file in cPanel

Start your project with WordPress in minutes. Trust our professional help and friendly staff – now all our shared hosting packages come with a 40% discount on the regular price! Check out our shared WordPress hosting packages!

Contact US