How to test if file exists with the tag <If ...> on Apache 2.4?
Asked Answered
T

2

15

I would like to test the existence of a file in my httpd.conf of Apache 2.4.

I use the tag like this :

<If "%{DocumentRoot}/maintenance.enable -f"> ...code to execute ... </If>

but my code is not good, apache's service doesn't want to start. I have read a lot of tutorials or docs on many sites but never found the answer :(

Please help me ...

Trilby answered 1/10, 2014 at 9:24 Comment(0)
H
22

You should read Apache error log as it might provide some hint on how it is interpreted.

Anyway, the right syntax is: <If "-f %{DOCUMENT_ROOT} . '/maintenance.enable'">

Headache answered 1/10, 2014 at 9:49 Comment(0)
F
6

For Apache 2.4.34 and later an alternate directive to use is <IfFile>.

In this case the syntax is:

<IfFile %{DOCUMENT_ROOT} . '/maintenance.enable'>
... code to execute ...
</IfFile>
Fatwitted answered 16/9, 2021 at 5:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.