1

I have a program writing and updating some RewriteRules in an .htaccess file (the main config is in the vhosts section). This works fine most of the time, but sometimes the file gets corrupt.

When this happens, the server responds with 500 Internal Server Error for every request because the .htaccess file is corrupt.

Is there a failsafe option or something I can configure to tell Apache it should ignore the .htaccess file if it is corrupt but respect it if it is ok?

Or at least is there a tool I can use to check regularly if the .htaccess file is valid (e.g. by cron job) and delete it if it is corrupt?

Dehalion
  • 175
  • 1
  • 10

3 Answers3

1

Try the Nonfatal option of the AllowOverride Directive. This is supported by Apache 2.4 and above.

You probably want to use this:

AllowOverride Nonfatal=Unknown
Alastair Irvine
  • 1,172
  • 10
  • 22
  • Seems like I was not the only one having this problem Nice to find out that there is now a solution for this. – Dehalion May 14 '17 at 11:43
0

No, there is no internal mechanism for linting .htaccess files. What you should do is include that sanity checking in your program, after all, it's pretty obvious where the corruption is coming from.

NickW
  • 10,183
  • 1
  • 18
  • 26
  • Yeah, its obvious, but its not my program so I would prefer another solution to editing and maintaining third party software :( – Dehalion Mar 11 '14 at 15:12
  • Well, there are plenty of sites which offer that sort of functionality, I wish I could suggest something, but I'd imagine integrating external web based scripts would probably be worse. Maybe a dev server to test it in? – NickW Mar 11 '14 at 15:56
0

the only way to "do" it is following:

# service httpd configtest && service httpd graceful && service httpd status
Syntax OK
httpd (pid  4580) is running...
# 

... as you can see it does it in it's own way, where it checks config and if its ok then it'll gracefully restart httpd and it'll show you status of it assuming configtest was ok, otherwise it won't go w/ graceful restart.

alexus
  • 12,342
  • 27
  • 115
  • 173
  • Does configtest check .htaccess files? Not being facetious, I can't find any info saying specifically yes or no. – NickW Mar 11 '14 at 16:10
  • @NickW `configtest` does _NOT_ check `.htaccess`, but the worse case scenario `.htaccess` would cause only one virtualhost/directory to be unavailable (due to error) Vs everything else that `httpd` is serving. – alexus Mar 11 '14 at 16:17
  • I hoped there would be something like configtest explicitly for checking one `.htaccess` file. apache itself does not check all `.htaccess` files in all directories of all vhosts (which is kind of obvious why). It would be great if I could run it for one specific file. Looks like I have to write a simple Syntax checker on my own :( – Dehalion Mar 11 '14 at 16:34
  • if you to use `include` that `.htaccess` into main file `httpd.conf` then `configtest` would check syntax of that file as well. – alexus Mar 11 '14 at 16:55