Home Did you know ? What is the use of htaccess file in PHP?

What is the use of htaccess file in PHP?

by Unallocated Author

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.

You may also like