How can I perform a syntax check on an .htaccess file in a shared hosting environment?

I have a build script (Perl) that modifies the .htaccess file when I deploy my applications. As a double-check, I'd like to be able to perform some sort of syntax checking on the created .htaccess file.

I am familiar with the idea of using apachectl -t however, I am in a shared hosting environment and because of file access restrictions I cannot read certain configuration files specified by the sysadmins. Apachectl simply will not work in this regard.

Ideas or suggestions welcome.


Solution 1:

There is no native .htaccess validator. If a third party tool exists, I am not sure if I would trust it. Since it is a script that modifies the file, you should be able to code the validation within your script.

You can also include testing and verification processes for your deployment, which would help reduce mistakes.

Solution 2:

Here two useful, free services:

This one lets you upload an .htaccess file for validation.
This one lets you paste the contents of an .htaccess file into a textbox for validation.

Solution 3:

The most reliable syntax checker is Apache itself.

If you can handle 500ms of possible downtime (the time it takes to make an http request to localhost, very approximately) then do this:

  1. Make a backup of the current htaccess file
  2. Replace the current htaccess file with the file to be tested
  3. Make a request to the server, for example "curl localhost"
  4. If the curl is not successful, place the backup back

Solution 4:

Using cool Text Editors like Coda for Mac or TextMate for Mac or maybe Notepad++ for PC, you can enable syntax highlighting, which might not be perfect, but will be helpful. .htaccess is written in Per, so just turn on Syntax Highlighting for Perl!