Htaccess With Few examples

Htaccess With Few examples

Htaccess(Hypertext Access) is a directory-level configuration file for Apache.The use of the .htaccess files is slow down your Apache server performance.htaccess is mainly used for the Apache users who don’t have permission to modify Apache configuration file.If u having access to httpd main server configuration file avoid .htaccess files completely.

Few .htaccess rules

Password protection

Make the user enter a name and password before viewing a directory.

AuthUserFile /home/example/public_html/.htpasswd-username
AuthName “Protected Directory”
AuthType Basic
<limit GET POST>
require Valid user

Deny users by IP address and allow others

Order allow,deny
Deny from
Allow from all

Allow users by IP address and deny other

Order deny,allow
Deny from all
Allow from

Rewrite Engine

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Its used to redirect to


Redirect 301 /linux/htaccess

To redirect http to https

ssl certificate is installed in server and we want to redirect all requests to https we use the following rule in .htaccess

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ [L,R]

To set the administrator email in .htaccess


Turn off the Server Signature

ServerSignature Off

Serversignature is used to protect from user to view the Apache version,its usually appears on error page.

To prevent directory listings

IndexIgnore *


Leave a Reply

Your email address will not be published. Required fields are marked *