ToolsToBlog_logo_quality_Final
Bloggers Library

Usages of .htaccess?

What are the uses of .htaccess?

.htaccess can be used to achieve the following

1) Display custom error messages
Custom error messages can be displayed whenever there is an error by configuring the .htaccess file as below

ErrorDocument 404 /page_error/404.html

This line tells the server to display the 404.html incase of a 404 error.

2)To set up redirects
Redirects can be set for the old pages with the new pages using the following

 Redirect /old_directory/xyz.html https://domain.com/newXYZ.html

It tells the server to redirect the requests for xyz.html to newXYZ.html

3)Password protect files and directories
Files and directories can be password protected with the following line
Protect a file as below

AuthUserFile /path/.htpasswd
Authtype Basic
Authname “Prompt”
Require valid-user

The first line tells the location of the password file. The second line tells the authentication type to be basic that is an HTTP authentication. The third line tells or prompts the user on the access of the file with this prompt. The fourth line tells the user to have valid login credentials to access the test.php.
Similarly, a directory can be password protected by using these as

AuthUserFile /path/.htpasswd
Authtype Basic
Authname “Prompt”
Require valid-user

4)Disable Directory Listing
Directory listing can be disabled/enabled by using the following

Options -Indexes   * The above line disables directory listing *
Options +Indexes   *The above line enables directory listing.*

However, if you want to disable listing of certain file types images directory the following can be mentioned in the .htaccess file

Indexingnore *.jpeg *.jpg *.gif *.webp