One of the things that are important in knowing how to manage a website is knowing how to work with the .htaccess file. This file can interact with the web server. Failure to control .htaccess and its proper management will cause many technical and even security problems for your website. Because of the importance of this issue, we’ve come up with a complete .htaccess training for you. We invite you to read this useful educational article.
Full .htaccess training
As mentioned, htaccess is the communication language of the website with the web server. So learning how to manage it is a very important thing. Below is a list of the items that can be managed by htaccess:
- Permanent and temporary redirects
- Control the access level
- Customize display settings
- Activate cache to increase website speed
The four above are most commonly used and explained below.
Note that in Linux, the point (.) At the beginning of each file makes it a hidden file. .htaccess is also a hidden file that has the point at its beginning. In the cPanel, to view this file, you should click on the Settings option in the top right-hand corner of the file manager after logging into the File Manager, and follow the image below:
Permanent and temporary redirects
One of the most important uses of .htaccess is the possibility of permanent or temporary redirects. Permanent redirects are known as redirects 301 and temporary redirects as redirects 302. From Google’s point of view, duplicate content should not exist on a website, and this is one of the basic ways to prevent duplicate content from appearing on the website. To get a complete idea of the subject, suppose we plan to install SSL security certificates on our website. As you know, the website will also be available via https. In this way, the site is currently displayed with two versions, http and https, which is the same content discussion duplicated. To resolve this issue, we must redirect the http version of the site to 301 on the https site. To do this, just enter the following value in the htaccess file.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourwebsite.com/$1 [R=301,L]
Note instead of the yourwebsite.com you should replace it with your website address. Also, if the website is www, you can insert it before the website address.
Control the access level
With .htaccess you can define several types of constraints and controls. Among them, there are two common models of IP restrictions and file access limitations that we will refer to below.
Limiting IPs
For example, we’re planning to unable view to the website with the IP 5.5.5.5. We need to put the following value in the .htaccess file.
Deny from 5.5.5.5
Or, if vice versa, no other IPs other than 5.5.5.5 can view the website, we need to set the following value.
Order Allow, Deny
Allow from 5.5.5.5
Deny from all
This can also be done for the IP suffering.
File Access Limit
Suppose we intend to restrict WordPress xmlrpc.php access to everyone. Then you need to put the following into your .htaccess file.
<Files xmlrpc.php>
order allow,deny
Deny from all
</Files>
Customize display settings
One of the things that cPanel of interactive tools are designed to do is manage the display settings. Suppose a path from your website contains just a few image files. With the cPanel indexed tool, you can specify how to display it. Click Indexes to access the Indexes after entering the cPanel in the ADVANCED section. You will see a list of your own directories on the page. For example, if you click on public_html which is the main content directory of the website, the four options below will be available for your selection.
Activate cache to increase website speed
One of the most common ways to speed up website access is to enable the cache. This makes viewers not have to recall part of the website’s content in the next visits and display it according to the previous visit. These can be text, patterns, and website structure that play an important role in increasing the speed of access to the website.