Things We Can Do with .htaccess

Simple text files used to configure web servers are .htaccess files. When you don’t have access to the native web server configuration file (like in shared servers) .htaccess files come handy. But you need to configure the webserver for rewriting or redirecting some web pages, allow and block access to certain hosts, etc. In this article, we are discussing the things we can do with .htaccess

Note that, you don’t need to reboot your server when you are making some changes in the .htaccess file, unlike the web server’s main configuration file. Changes are effected immediately instead.

Here are some of the things we can do with .htaccess.

Customize Error Messages

You can use .htaccess to define your messages if you want to override the server’s error pages. An example of the syntax is:

ErrorDocument 500 /error.html

Enable Directory Browsing

This is also important in the things we can do with .htaccess. Most web hosts will not allow directory indexing, due to security concerns. When the directory does not contain an index page, the option allows the contents of a directory to be displayed in the browser.

For example, if you make an HTTP call to a directory such as, it would list all the images in that directory without the need for an HTML page with links.

You can still set this option if you require it on specific directories. By adding the following line to your .htaccess file, you can reactivate it.

Options +Indexes

The directory will fully index again once you add this.

Block Users from Accessing Your Web Site

If you want to deny access to a particular individual, and you know the IP address or domain name that the person uses to connect to the Internet, you can get the use of .htaccess to block that individual from your website.

<limit GET>
order deny,allow
deny from 123.456.789.000
deny from 456.78.90.
deny from
allow from all

Redirect Visitors to a New Page or Directory

Think you re-do your entire website, renaming pages, and directories. Visitors to the old pages will receive the 404 File Not Found error. by redirecting calls to an old page to the new page, you can solve this problem. As an example, if your old page was named oldpage.html and newpage.html has replaced that page, add this line to your .htaccess file:

Redirect permanent /oldpage.html

You want to replace with your actual domain name. Now, when the visitor types in, they will be automatically redirected to

you can use one redirect line to affect all pages within the directory if you’ve renamed a directory.

Redirect permanent /olddirectory

The directory or old page is specified using the system path relative to your www directory. And the absolute URL specifies the new page or directory.

Leave a Reply

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

ten + 13 =

30 + = 40