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.
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.
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.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:
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!
You can simply use Notepad++ for syntax checking.
Silas Brill has been gracious enough to create a custom language for htaccess files and share it here. http://notepad-plus.sourceforge.net/commun/userDefinedLang/Htaccess.xml
Just go to View -> User-Defined-Dialogue -> Import
and restart Notepad++. You should be able to see the new language under the Language option.