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.
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 ^(.*)$ https://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 ^(.*)$ https://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.
Hi Bruce, Unfortunately not.
<br />It is fussy about the hash only appearing as the first character on a line. If the hash appears after another command it will likely cause an internal server error.
Must a comment always start on a new line? Could I for instance put a comment at the end of a line eg
RewriteCond %{HTTP_HOST} !^www.daftlogic.com$ [NC] #Redirect all non-www traffic to the www version ?
Perfect Answer, Thanks!
On 8th June 2016Thanks!
By Alex on 20th April 2016Thanks, Daft Logic.
By Luis on 27th March 2016ASD
On 18th January 2016Hi, this requires you use multiple # symbols per line, so no, there is no multi line method.
By Daft Logic on 18th March 2015Any way to make a block comment e.g., for multiple lines?
On 18th March 2015Thanks !
On 8th December 2014allo
On 30th November 2013Thanks, comes in v.useful
By Jamie on 18th December 2012ThanK You
On 8th August 2012awesome. thanks.
On 4th March 2011Just what I needed to know! Cheers
On 30th June 2009thanks
On 23rd February 2008There's no need to create an account or provide unnecessary details. Just your comment.