.htaccess – A quick guide

.htaccess , Whats is it?

According to Apache:

.htaccess files (or “distributed configuration files”) provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof

‘Directives’ usually refer to the commands that are contained in the .htaccess files, which control or modify your server’s various behaviours. Many free and paid web hosts permit you to change and modify your .htaccess files but remember if you have a website running on Yahoo Geo Cities,Goolge sites or freewebs then this article is meaningless for you cause they dont allow access to .htaccess files

What can you do with .htaccess?

.htaccess can be used in many different creative ways , but its most common usage is for:

  • Setting up custom 404 error pages
  • Enable/Disable directory browsing
  • Change default homepage for a directory
  • Block certain users from accessing your site
  • Block specific refferers
  • Prevent certain files from being viewed
  • Block Hotlinking

How to create one?

Create a text file from any text editor, Note Pad,Text Pad and save it as .htaccess ( remember the period before htaccess and no .txt extension ).
Upload it in your home directory…The rules in .htaccess file apply to all the sub directories in your files directory

Doing some cool stuff

Now here comes the real thing…
To enable your server to use a custom 404 file not found page for broken links or URL typos…
include the following code in your .htaccess file:

[code lang="php"]
#The page notfound.html should be in the same directory as your .htaccess
ErrorDocument 404 /notfound.html 

#Alternatively you can specify just raw html to be used instead of a page
ErrorDocument 404 "<h1>yikes! that  page passed away a while ago...</h1>"

Enable / Disable directory browsing
[code lang=”php”]
Options +Indexes
## Block some specific file types from showing
IndexIgnore *.avi *.mp3 *.pdf

Change directory homepage

[code lang=”php”]
##the pages are used in order
DirectoryIndex myhomepage.html index.html index.php

Block some users from accessing your site
[code lang=”php”]

order deny,allow
deny from
deny from
deny from .hackers.com
allow from all

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

2019 All rights reserved | Powered by WordPress
Back to top
Theme by dynamicguru.com