Useful .htaccess Rules

September 30, 2007

Here are a list of useful .htaccess rules that can be used with your web development.


Create a custom Error Message

Add the following line of code to your .htaccess file:

ErrorDocument 404 http://www.yourdomain.co.uk/error-page.html

This enables you to create a customised 404 error page, this is the page that appears if browsers go to a page on your site that no longer exists.

The next .htaccess instruction is very simple but can also be very useful,

Change your Default Home Page

Many Servers will use either index.php or index.html as the primary page when some one types in your domain; the following instruction allows you to chose whatever name you want for the default page.

Add the following line of code to your .htaccess file:

DirectoryIndex filename.html

This could be useful if you want to run a blog like wordpress from the route of your website, but also would like a stand alone page before hand.

The last .htaccess modification is to enable static pages (.html) to use PHP functions within them.

Use PHP in a HTML Page

Add the following line of code to your .htaccess file:

AddType application/x-httpd-php .html

If you want to use PHP in .htm files simply change the .html to .htm.

Neil
Head of SEO

  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • Wists
  • Furl
  • Spurl
  • Technorati
  • YahooMyWeb
  • Ma.gnolia
  • Reddit
  • Simpy
  • StumbleUpon
Listen to this podcast Listen to this podcast

No Comments

No comments yet.

RSS feed for comments on this post
TrackBack URI

Leave a comment