8

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.

John Gardeniers
  • 27,262
  • 12
  • 53
  • 108
Danny
  • 311
  • 3
  • 10
  • But even if you could run `apachectl -t` it is used for virtualhosts only it would not serve to your needs. My best guess would be that you gona need to make your own validator ... perhaps asking in the stackoverflow.com will get you a lead of how to go thru about this. At any rate this is more programming related from what i see. – Prix Aug 28 '10 at 17:37

5 Answers5

2

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.

Warner
  • 23,440
  • 2
  • 57
  • 69
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.

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
oce
  • 21
  • 2
  • 2
    Welcome to Server Fault! Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Scott Pack Aug 26 '12 at 00:01
  • 1
    Also, a link and run like that does generally tend to get flagged as spam, so next time, it may be wise to consider adding some content and context into your post. – HopelessN00b Aug 26 '12 at 03:09
2

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
fregante
  • 121
  • 4
  • In general, functionality checks like these should be a standard part of your deployment environment. Good stuff! – womble Sep 10 '15 at 03:52
  • +1, as misconfiguration might happen even with the valid syntax you will want such a step in any case and this will handle the syntax as well. – Mark Kaplun Mar 12 '19 at 05:48
1

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!

Adam E
  • 11
  • 1
0

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.

Abbas Gadhia
  • 323
  • 1
  • 3
  • 10