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 |
|---|
| PHP Introduction |
| PHP Terminology |
| PHP Installation |
| PHP Syntax |
| PHP Comments |
| PHP exit() Function |
| Exercises & Assignments |
|---|
| Write a program to print “Hello World” using echo |
| Simple Tips for PHP Beginners |
| Experiment with Basic PHP Syntax Errors |
| Using phpinfo() – Display PHP Configuration & Modules |