18 March, 2023
What Is the .htaccess File? How to Use and Edit It

What is the .htaccess file? how it works and related useful information are essential when developing a website to meet practical needs, and there is a lot to learn and a lot of knowledge to cover. Having the basics helps us pick up techniques to use the .htaccess file better and more effectively. Let's MONA Media learn about all of this in this article.
What is the .htaccess file?
The .htaccess file (HyperText Access) is a configuration file on Apache web sever that is widely used on WordPress websites. Put simply, .htaccess is a file that controls how files in a specific directory are accessed.
It is known as a powerful tool for improving website securityand performance on WordPress as needed. With a few small edits you can create redirects, block attacks, deny access from certain regions of the web, block users, and more.

The .htaccess file is a powerful tool for improving security
How to use .htaccess?
To work with the .htaccess file you need any editor that supports code text, such as PHP Designer or NetBeans, or even the Notepad that comes with Windows.
The .htaccess file is not written in any programming language. It is built from Regular Expression rules. So without the necessary knowledge, working with .htaccess files is difficult and takes more time and effort.
Also, even a very small mistake in the file can make the website show a 500 error. In effect, you have just broken your own website. So be extremely careful when editing the .htaccess file, and never forget to keep a backup before you touch it.
This file is usually located right inside the root directory of the hosting, where it is easy to see. Using it is simple and mistakes are kept to a minimum.
Notes when using .htaccess
When using .htaccess, make sure the file is kept as secure as possible so bad actors can't exploit it to harm your website. To guard against problems, it is recommended to save a copy of the .htaccess file before editing.
If users don't know the file well, or make even the smallest slip during configuration, your website may stop working or no longer work as well as before. So saving a copy of the .htaccess file needs great care.
What the .htaccess file does
The .htaccess file has its own uses and benefits. The main ones are:

The .htaccess file has its own uses for WordPress websites
- As one of the CMS largest and most widely used platforms today, WordPress attracts hackers. So keeping the site safe, at the highest possible level, is always an admin's top priority. You don't have to be a coder or developer to use the .htaccess file to add security to your website. This is its biggest and most important benefit.
- In addition, being able to handle logic for any request without reloading or restarting the web server is also a benefit not to be overlooked.
- With the .htaccess file, users who are not administrators can also make adjustments without affecting the whole APACHE configuration.
- The .htaccess file is also valued for making it easy to set access permissions for users and ensure they can only access their own folder.
- The .htaccess file also suits content management systems.
Basic .htaccess configuration guide
Configuring the .htaccess file takes a few simple steps, and there are several ways to do it. The 3 main ways are:
Method 1
- Step 1: Open a text editor on Windows. You can use Notepad, then type the sample code below, paste it into the .htaccess file and save. The code is:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
- Step 2: The file is then uploaded to the public_html directory if the host is DirectAdmin. This is not an official method, but it is simple and can be used if you don't know the other methods.
Method 2
- Step 1: Log in to your hosting account provided by your hosting provider, using your username and password.
- Step 2: Right-click an empty area in File Manager and choose New File.
- Step 3: Finally, enter the name .htaccess and click Create to save, and the file is created as required.
Method 3
- Step 1: Access a Linux system and create a .htaccess file.
- Step 2: At this step, copy the created file to Windows, or use a Linux hosting account to create the file and download it.
- Step 3: Compress the file before downloading, and extract it fully after the download succeeds.

Configuring the .htaccess file
How to edit the .htaccess file
The .htaccess file is present by default when WordPress is installed, and is usually in the root directory of this CMS. It is a single file with no other files or any other extension.

Choosing the .htaccess file
Just open it with Notepad, Notepad++ or similar software. One special requirement: never add code to, or edit, the area between #BEGIN and #END. When you need to, the best approach is to add the new block below it. When editing, keep in mind:

Adding code to .htaccess
- After adding a block of code, make sure you save it.
- If you insert several different blocks of code, don't add them all at the same time.
- Adding them one by one lets you tell where an error is, so fixing it is faster and simpler.
Finding the .htaccess file on hosting with cPanel
For users on Web Hosting with cPanel as well, finding the .htaccess file is very easy. A few simple steps will do:
- Completing "log in" to your hosting account, then click “File Manager” in the Files section. You will see the .htaccess file right inside the public_html directory.

Click File Manager to find the .htaccess file in cPanel
- If you don't see it, click “Setting” in the top right corner of the screen, then click “Show Hidden File”.

Choose Show Hidden Files
- If your hosting doesn't have the file, you need to create one. Click the icon "+ File in the top left corner", or left-click an empty space and choose “New File”. Then "enter the file name .htaccess" and click “Creat New File” to finish.

Click Create New File to finish
When developing a website with WordPress, learning about file .htaccess is essential. We hope the useful information above gives you more knowledge you can apply when developing and managing a WordPress website for real work needs.
FAQ
What is the .htaccess file used for?
What do you edit the .htaccess file with?
Related articles
Professional website
design services
Own a website with a beautiful, 100% exclusive design and a lifetime warranty, with the ability
to expand features flexibly as your business grows, starting today!































Free AI courses
AI tools at work
VI
EN
