• Home
  • Download Free eBook
  • OC Archives
  • Tools I Use
  • Webmaster Forum
  • Write For Us
Logo

  • Discounts
  • SEO Central
    • All other Search
    • Bing
    • Google Central
    • Yahoo
  • Social Networks
    • Digg
    • facebook
    • Squidoo
    • Technorati
    • Twitter
  • Web Design & Development
    • Ajax
    • Coding
    • Database
    • Graphic Design
    • Joomla
    • jQuery
    • OScommerce
    • Photoshop
  • Webmaster Central
    • Author's Corner
    • Case Studies
    • Content Writing
    • Featured Interviews
    • Guest Posts
    • Make Money Online
    • OC Promos
    • Premium Reviews
    • Video Tutorials
    • Web Hosting
    • Web News
    • Web Security
  • Wordpress

.htaccess – All you wanted to know and much more!

Posted by Joshu on Nov 5, 2010 in Coding, SEO Central, Tutorials, Web Design & Development, Webmaster Central, Wordpress | 0 comments

What is .htaccess and why is it so important

 Even though .htaccess is just a file, it has a huge importance for your website and its contents. It could change the settings of your web server and you could do a lot more with it.

 Most popular uses of .htaccess files are:

  • Completely customized 404 Error pages
  • 302 redirects
  • Allow or deny settings to user groups
  • Forbidden setups
  • Password protection of folders
  • Change file extensions
  • Banning users with certain IP address
  • Using a different index file
  • Hide folders and files inside it on your web server.

First find out if htaccess is allowed by your hosting provider

Usually most of the hosts allow htaccess and if it’s a Linux server with apache as the web server ideally it should allow the usage of the file, further it depends on the permissions that your host has provided on your web hosting to let you or not let you use it.

How to create an .htaccess file

Simply open a note pad, paste the contents of your intended .htaccess file and save as “all file types” and name file with extension .htaccess and upload it to your ftp in root of your website.

Usage 1: Create Custom error pages

This is one of the main and simple usage of .htaccess files – you can create completely customized and more professional error pages and use them instead of the default one provided by your web host. I bet you would have wondered if I could change the crying alligator error message and have my own. Well find how to do it below.

As long as you know the error number you could use it for any error page.

The syntax for usage is as below:

ErrorDocument errornumber /file.html

For example: ErrorDocument 404 /customerror.html  (for a 404 error)

Some of the commonly found errors are:

These are some of the most common errors:

401 – Authorization Required
400 – Bad request
403 – Forbidden
500 – Internal Server Error
404 – Wrong page

Simply add the code to your website .htaccess and upload the customerror.html page you want to display in each case

Usage 2: Hide listing of directory index

In some case when some user accidently types in a sub directory name in the browser of your web server, it lists the folders and files under it and this is serious security vulnerability. This vulnerability can be closed with the help of a simple .htaccess file

Just add a new line to your htaccess file

Options –Indexes

Usage 3: Banning users or spammers from specific IP address

 In some cases you would want only specific IP address to use or not use your directory or website, in such a case add the below line to block an IP address.

 Deny from xxx.xxx.xxx.xxx

Example:

Deny from 169.189.3.2 – This will block the specific IP address

Deny from 169.000.000.000 – This will block the specific IP range post 169

Usage 4: Usage of alternate index files

Usually in a root web directory or any web directory the index file would be either index.html or index.htm or index.php or default.htm

What if you wanted to change this to another one say whiskey.beer?? Yes htaccess has the answer! It could even change the default file name as well as the default extension.

Alternate index files can be used with the below line added and the server would read from left to right and skip if file not present and use the next file as default. Below is the syntax

DirectoryIndex index.htm whiskey.beer index.html

Usage 5: Simple Redirections

This is one of the most useful functions of the .htaccess file you could easily set redirections from one file to another, one directory to another or even one website to another.

In case you want to redirect the root index.html file to another folder or

Redirect 301 index.htm http://www.samewebsite.com/newfolder

Or Redirect 301 index.htm http://www.anotherwebsite.com/newfolder

Or Redirect 301 index.htm http://www.samewebsite.com/anotherfolder/anotherfile.htm

OR Redirect /olddirectory http://www.anotherwebsite.com/newdirectory

Redirects note: File name is simply used at the first half of the command for redirects when the .htaccess is in the same folder as of the first file.

Note: These syntaxes could be simply added to your .htaccess files as a simple line and then uploaded to find the effect.

If you have ANY questions regarding the .htaccess – please add a comment here, I will help you out.


Related Articles You Are Probably Interested In:

  1. ’500 Internal Server Error’ in WordPress & the Solutions
  2. How to solve Fatal error: Allowed memory size exhausted in PHP
  3. How to avoid 404 Page not found errors on your website
  4. How to Transfer a WordPress Blog to a new Server
  5. WordPress admin login – blank white screen
  6. Learn how to upload files to website FTP
  7. Firebug Plugin For Firefox – All you wanted to know about Firebug
  8. 500 Internal Server Error after upgrading WordPress

Leave a Reply Cancel reply

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

*

*

CAPTCHA Image
Refresh Image

*

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>

 Subscribe to OC Blog! 

Subscribe to OC Blog

Stay tuned to the Latest updates and tips in the Webmaster World




Most Popular Posts

  • List of High PR do follow blogs (Verified) (321)
  • Next Google Page rank - PR update 2011 (284)
  • Market Samurai Discount – Save 80 USD! (235)
  • 300 High paying adsense keywords 2011 (106)
  • List of High PR Dofollow Directories 2011 (95)
  • 22 OpenSource Forum Scripts - Details and Download: update list (82)
  • Best Classifieds Ads Scripts (77)
  • How to modify the Wordpress comment Form (67)
  • Review of the List of the Best Social Networking websites 2011 (61)
  • List of 200 Highest paying Adsense Keywords : Updated list 2010 (44)
  • Featured Interviews: Harsh Agarwal from ShoutMeLoud.com (44)
  • 10 Best Premium Wordpress Plugins (43)
  • Elegant Themes Discount 2011 (Save 10 USD) (42)
  • List of all Top Social Networking websites as on 2010 (38)
  • One of the Biggest SEO Secret for Linkbuilding (37)
  • 14 Best Ajax Scripts to use for any website (37)
  • Download KeywordLuv WordPress Plugin (37)
  • How i earn Big Bucks from my blog Doing Nothing! (37)
  • Fatal Error on WordPress 3.3 Version Upgrade (37)
  • 30 Best wordpress Plugins required for Any WP Blog (36)
About OrangeCopper Network 

Who am I? Am Joshu. I enjoy blogging about webmaster related stuff and technology. Xtras - I Design, Develop, Blog and Support the Open Source. Passions: I Love Music, Photography, Design, Development, Cycling, Travelling and sleeping (Favorite)

What i could do for you: Ive been working on various shades of the web for over 11 years now and learned the hard way, Now i could help you learn it the Easy way. OrangeCopper is a Webmaster community that i started in the year 2002 and is now a platform for webmasters around the world. Thankyou for spending your time to visit Blog. I would love to get connected every webmaster reading this, follow me on Twitter and i would auto follow you. Thanks again, Happy Surfing!

Interested to Learn Professional Blogging? Check out my NapIncome Blog where I share all the secrets to build a professional blog and earn money from ProBlogging.

Please Subscribe to the Blog Newsletter to get regular weekly update
Twitter: http://www.twitter.com/orangecopper | Subscribe to feeds : http://feeds.feedburner.com/orangecopper/ilRl

Other OrangeCopper Network Websites

ConnectRing Web Directory | UsedMobiles.in | UsedGadgets.in | NapIncome Strategy Blog | HippieMonk Technology Blog | All Good WordPress Themes | PixelTribes Photography Blog | Yscream Web Hosting

Favorite Articles

  • List Of Best Classifieds Ads Scripts Ever (Free & premium)
  • How to triple your Blog Subscription rates / opt-ins – It Worked for me!
  • You can certainly spend Half a Dollar For creating a GREAT Blog
  • How i earn Big Bucks from my blog Doing Nothing!
  • 35 best free wordpress themes for download: updated list 2010
  • 22 Web 2.0 Colors and their codes in HTML
  • 48+ web Design Related Twitter Accounts To Follow
  • Make a web 2 icon with Photoshop in easy 8 steps
  • List of 62 Free Press Release websites

    Most Rated Articles

  • Compare WordPress – Joomla – Drupal and their features
  • 7 Excellent jQuery menus and jQuery examples and downloads
  • 5 Most Important To Do s for a New Blog Launch
  • How to colorize with adobe Photoshop
  • Free Magento Themes / Templates Download: updated list
  • How to install wordpress step by step tutorial
  • List of 200 Highest paying Adsense Keywords : Updated list 2010
  • How to display Exit Splash or Exit message for website
  • How to promote your old Blog posts