More Fun With .htaccess Files

December 7, 2007

3 things you can do with .htaccess files that we probably haven’t mentioned on this blog before:

1). Put error messages in the .htaccess file as opposed to creating separate web pages. There is no real reason to do this. However, it is pretty cool, in that you can pretty much create a website using just an .htaccess file and no other files.

ErrorDocument 404 "<html><head><title>This Is a Demo</title>
</head><body>Here is some cool stuff:<ul><li>Some text</li>
<li><a href='/'>A Link</a></li></ul></body></html>"

2). Use mod_rewrite to rewrite a URL internally with no redirect. I don’t believe that we have ever covered this, but it is very handy:

RewriteEngine on

RewriteRule ^happyurl\.php$ crazyurl.php?with=some&extra=bits[L]

3). How about using mod_rewrite to redirect any queries to a certain page if the page/directory that is being accessed doesn’t exist.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /oopsydaisy.php [L]

Note, don’t get this confused with with error documents. This .htaccess rule give out a 200 OK in the http headers, which tells search engines that the pages exists, where as the error document will give out the relevant header - 404 or whatever, telling the search engines what the issue with the url they are accessing is.

James
SEO Programmer

  • 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

1 Comment

  1. James.

    I have just bought a domain that has a few hundred pages. As I’m re-developing the site I have removed all these pages. However the bots are currently still looking for them - should I just let them not find them and then they’ll de-index them over time or should I do something fancy with the .htaccess file?

    Comment by gadget December 7, 2007 @ 5:00 pm

RSS feed for comments on this post
TrackBack URI

Leave a comment