How to create default WordPress .htaccess file? »Compa Marketing

Anyone can build and run a WordPress site without any knowledge of basic files and directories.

But one day, you may find yourself in a situation where you need knowledge of WordPress files and folders. Sometimes you will need to fix the problem or make corrections. That will require you to go behind the scenes and access your WordPress files.

Get the .htaccess file, for example. This is one of the most important WordPress files and users can perform a lot of functions by modifying it. They can fix common WordPress errors, password protect certain pages on your site, restrict access to WordPress files, block IP addresses among many other things. But sometimes it's hard to locate the file.

Reason?

Well, when you install WordPress, the .htaccess file is automatically created. When WordPress cannot have the rights to automatically create files (possibly for reasons such as a server causing an obstacle), you will need to manually create the file and upload it manually. This is not difficult but the process is risky.

As we mentioned, the .htaccess file is an extremely important file and a single error while processing the file could break your site. But don't worry, we have a tried and tested process that will help create .htaccess files and upload them with care, without breaking your site.

What is a .htaccess file in WordPress?

We mentioned earlier that the .htaccess file is automatically created when you install WordPress for the first time. The file allows you to give instructions to your web host. You may want to modify your website settings, redirects or apply security measures. To make these modifications, all you need to do is edit the .htaccess file and add the code snippet.

Where is the .htaccess file located in WordPress?

The .htaccess file is found at the root of your WordPress installation. What does it mean? Take a step back.

WordPress websites are made up of many files and directories. If you can return to the scene of accessing your files through the File Manager, you will find that there are many WordPress directories and subfolders. The largest WordPress directory in every WordPress installation is the public_html directory. It is sometimes also called the root directory or the root directory.

You will find your .htacesss file in this root directory. We will show you the exact steps you can take to locate the .htaccess file in the next section.

How to find a .htaccess WordPress file?

But be patient to find the .htaccess file, you will need access to the backend of the website, which makes the process risky. A mistake can cause your website to crash. So make sure you are making a complete website backup. If an error occurs, you can restore your site to normal.

Step 1: Log into your hosting provider's account and access your cPanel and select File Manager. You can also use any other ftp client like Filezilla.

Step 2: When you are a File Manager, click on the public_html folder and look for the .htaccess file in that directory (see image below).

IMPORTANT: WordPress often hides a .htaccess file to prevent people from playing around with important WordPress files. If you cannot find your .htaccess file, it will probably be hidden. Don't worry, we'll let you know exactly how you found it.

Step 3: From File Manager, select Settings usually located in the right corner of the page. A popup window will appear in which you will need to select the option Show hidden files. Save changes and return to File Manager. In the public_html directory, you will find the .htaccess file.

If you still cannot view the .htaccess file, your website may not have the .htaccess file.

We mentioned earlier that under certain circumstances, the .htaccess file may be missing from your site. For example, your web server prevented WordPress from creating a file or one of your users may have deleted it. In such cases, you need to create a new .htaccess file and show you exactly how you can do it.

How to create a WordPress .htaccess file?





There are 2 ways to create a .htaccess file -

  1. By placing Permalinks
  2. Create .htaccess manually

Earlier in the article, we talked about how you can perform many functions such as redirecting and keeping your site password protected with the help of your .htaccess file. But on its own (i.e. no one makes any modifications to the file), WordPress default .htaccess file has a few tasks to perform. These actions are related to your site permalinks. You will need a .htaccess file to ensure that your website URL is working properly. Because permalinks are closely associated with the file, they will allow you to create one. This is the way

Log into your WordPress website and navigate to Settings> Permalinks. Scroll down the page and click Save Changes.

This will create a .htaccess file, but to be sure, log into your WordPress hosting account and go to File Manager. From File Manager, select public_html and in this directory you will find the .htaccess file.

2. Create .htaccess manually

In rare cases, WordPress may not be able to create a file because your web server is refusing permission to create the file. In that case, you will need to create the file manually and upload it to your website.

a. Open a text editor like Notepad on your computer

b. Now copy and paste the following code into the editor

# BEGIN WordPress

RewriteEngine On

RewriteBase /

RewriteRule ^ index.php $ - (L)

RewriteCond% {REQUEST_FILENAME}! -F

RewriteCond% {REQUEST_FILENAME}! -DRewriteRule. /index.php (L)

# END WordPress

c. Save the text file as a .htaccess file

IMPORTANT: Make sure that the file name is not simply ht htaccess - it has a complete stop (.) When starting. Make sure there is no extension like .txt

d. Now it's time to upload the files. But before you do that, make sure you back up your site yourself. If everything goes wrong, you can restore your site to normal.

Log in to your hosting account and go to File Manager. From File Manager, select the public_html directory (the htaccess file will be saved in this directory). Then select Upload and upload the .htaccess file from your computer.

And that is it. You have successfully created a .htaccess file for WordPress website.

Final thought

If you are planning to work with WordPress websites, learning about .htaccess is a step in the right direction. There are many functions that you can perform on your website with the help of .htaccess files. Once you understand it, all you need to do is open the .htaccess file, add the code and a new function will be at your fingertips.

But working with .htaccess is like stepping on an eggshell. One slip and you can end up causing your website to crash. Therefore, you need a safety net. Back up your entire site so that if you make a mistake, you don't need to worry. Just restore your backup and get your site up and running right away.

About My name is Nguyen Manh Cuong. I was born in a poor village in Ba Vi district, HA NOI province - windy and sunny land. Currently. https://www.nguyendiep.com/. Mr Cuong.
Newer Posts Newer Posts Older Posts Older Posts

Comments

Post a Comment