What is .htaccess and why do we use it?
.htaccess (hypertext access) is a configuration file of the Apache web server. You can put it in any folder of your website, and the rules inside it apply to that folder and its sub-folders. The big benefit is that you can change server settings without touching the main server configuration.
Common uses of .htaccess:
- Redirect pages and force HTTPS
- Block or allow access to files and folders
- Password protect a directory
- Show custom error pages (404, 500)
- Enable browser caching to make the site faster
- Add security rules and hide the directory list
# Stop showing the list of files of a folder
Options -Indexes
Note:
.htaccess works only on Apache (and compatible servers like LiteSpeed). Nginx does not read it. A wrong rule can break your site with a 500 error, so always take a backup of the file before you edit it.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |