Logic, but in a different way

Daft Logic

Adding Comments to a .htaccess File

Last Updated 11th November 2007

Introduction

Using the .htaccess file in Apache web server is a bit of a pain, although its hard to steer away from it. To help organise your htaccess file, like any other code, it is useful to add comments.

How To Add Comments

Simply enough, it is a case of using the # (hash) symbol.

So for example for Daft Logic, we may have a file such as ...

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.daftlogic.com$ [NC]
RewriteRule ^(.*)$ http://www.daftlogic.com/$1 [R=301]
RewriteRule ^(['_A-Za-z0-9-]+).htm$ /?showpage=$1 [L]

Could be re-written as...

RewriteEngine On

#Redirect all non-www traffic to the www version of site (prevents possible duplicate content)
RewriteCond %{HTTP_HOST} !^www.daftlogic.com$ [NC]
RewriteRule ^(.*)$ http://www.daftlogic.com/$1 [R=301]

#Rewrite all pages ending in .htm to the index page, with the preceding string as the showpage GET variable
RewriteRule ^(['_A-Za-z0-9-]+).htm$ /?showpage=$1 [L]

As far as Apache sees there is no difference as it ignores the lines starting with #, but it can be much easier to see what's going on. This is helpful because the nature of the htaccess file means you do not use it day in day out, but are more likely to forget about it for a few months and when you look at it again it is easy to forget why it is what it is.

Previous Comments For This Page

thanks
On 23/02/2008

Add your own comment below and let others know what you think:

Comments :

Your Name (optional) :