What is the use of htaccess file in PHP?

htaccess stands for Hypertext Access and is a configuration file used by Apache-based web servers that manage live directories.

htaccess file is a method to configure the website details without required to modify the server config files. With the period that starts the file name will keep the file hidden within the folder.

The .htaccess file can be created in any text editor (name it only .htaccess without any other extension or name) and then upload it to your site through an ftp client or file manager.

The position of the .htaccess file is important. The configurations in that file will affect all the files in the current directory and the directories under it.

Here are some uses of the file in apache server:
– Customized errors: Modifying the page that is displayed when a server-side error happens, for example, HTTP 404 Not Found.

– Rewriting URLS: Servers usually use the file to rewrite “dirty” URLs to shorter and prettier ones.

– Cache control: The file enable the server to control User agent caching that is used by web browsers to decrease bandwidth usage, server load, and perceived lag.

– Authorization, Authentication: The file is usually used to define the security limitations for the directories, hence the filename “access”. The  file is usually accompanied by an .htpasswd file which stores valid usernames and their passwords.

Related posts

How to Improve Your Cyber Resilience by Strengthening User Privileges

The Dark Side of Viral Content: How Negative Reviews Can Snowball

Testing Gaming Monetization: Walking the Line Between Profit and Player Experience