Search A2Z 24

Basics of htaccess with examples

.htaccess is short for Hypertext Access.
.htaccess has no file name and it starts with a period and ends with the extension.
.htaccess file is a configuration file used by Apache based web servers, and is used for configuring the details of your website without altering the server configuration files.
The file is a hidden plain text file and is used to control the directory in which it resides, as well as the subdirectories below.

Example functionalities of .htaccess:

  • Ability to  block specific IP address from being able to view your website
  • create and use custom error pages
  • Create a clean and friendly URL
  • Domain redirects
  • Disable directory listing
  • Hiding file extension

The ability to  block/ban specific IP address

Block individual IP address:

order allow, deny
deny from
deny from 
deny from 
allow from all

Block a range of IP address:

order allow, deny
deny from 192.168.
deny from 110.1.1.
allow from all

Create and use custom error pages

  • 400 – Bad request
  • 401 – Authorization Required
  • 403 – Forbidden
  • 404 – File Not Found
  • 500 – Internal Server Error
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreq.html
ErrorDocument 403 /errors/forbidden.html
ErrorDocument 404 /errors/filenotfound.html
ErrorDocument 500 /errors/internalservererror.html

Disable directory listing  

Options All -Indexes

Domain redirect ie. olddomain.com to www.newdomain.com

RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Hiding file extension

http://www.mywebsite.com/index.html  to  http://www.mywebsite.com/index

RewriteEngine on
RewriteRule ^([^/.]+)/?$ $1.html

Create a clean and friendly URL

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1

About Author

by Admin

Share your thoughts!

Login as a member to access comment posting block !! click-here

Thoughts From Other Users (0)

No Comments

Reveal Modal Goodness

This is a default modal in all its glory, but any of the styles here can easily be changed in the CSS.

This is just a simple modal with the default styles, but any type of content can live in here. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quis sem vel enim eleifend tristique. Etiam tincidunt faucibus pharetra.