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

Want to learn more about apache? Try this resource...

Apache Cookbook: Solutions and Examples for Apache Administrators
  • How do you get RID of the .htaccess page? it crashes my site . Can I just delete?

    • Andrew

      Saundra, yes you can delete it. Websites running on apache do not require the .htaccess file. Make sure you backup the file before you delete it. Blogs commonly use them to perform tasks like search engine friendly URLs.

  • Hi

    we’ve got our site in 2 parts. 1 part done in wordpress the other in straight html.

    there seem to be 2 .htaccess files.

    for doing redirects on some of our wordpress pages which would you recommend editing?


    • Andrew

      In briefly looking at your URL, it looks like your WordPress site is under the ‘guides’ directory. If that is the case the you can edit the .htaccess file in the guides folder on your server. However it would be best to just manage redirects from the .htaccess that is in the root location of your web folder. Regardless of the location, place any hard redirects before any of the WordPress .htaccess edits.

  • Anthony

    I am trying to figure out how to code the .htaccess file to redirect ios (iphone, ipad, itouch) to a standard html page (e.g. /ios/index.html). this is due to use of full flash on the master site.

    I was told that .htaccess will handle this. but I am feeling really dumb!

    Any assistance would be soooo appreciated.

    Thank you,

  • David Ashby

    I am just doing a project via Youtube, I am at a stage where I am putting up a .htaccess file. The problem is that the project is buried in the depths of my site 3 folders down and I am having trouble configuring the .htaccess file within the project dir. Can you also tell me is this likely to cause an issue with my main site as there is a .htaccess file in the root. I have no idea regarding this file at the moment. Thanks for any advice.

    • eppand

      It is possible. .htaccess rules are inherited in sub directories. So you may have to ‘cancel’ out some inherited actions if they parent directories are creating issues.

  • gaurav

    im always getting Internal Server Error when i put .htaccess file with the same code that you have written.

    • eppand

      Are you updating the domains to be applicable to your situation?

  • webhoster

    I was reading that tutorial and I just don’t understand why in the heck, /user/joe/x won’t match the pattern?

    It starts with user just like the pattern is looking for.