How to comment in a .htaccess file

comment htaccess fileThe .htaccess file is commonly used to redirect traffic and search engines to pages that have been moved or when an entire site moves to a new domain. Developers will commonly include comments in code to instruct what the next snippet of code will do. This commenting standard helps for projects that are managed by a team or may be transitioned to another developer.

Commenting in the .htaccess file is done by adding a # at the beginning of the line(s) that you would like to comment. The # is required before each line of comment. Essential this instructs the server to ignore that line in the .htaccess file.


# redirect section
RewriteEngine onRewriteCond %{HTTP_HOST} ^domain-one\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain-one\.com$
RewriteRule (.*)$1 [L,R=301] 
# end redirect section 
# another comment line