Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
    
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

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.