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

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
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,289
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
  • 13,667