Maxim Neaga
Maxim Neaga

Reputation: 961

Apache Rewrite if file exists

If offline.html exists in the root directory, rewrite to it.

I created the following .htaccess file and placed it in the root directory:

RewriteCond offline.html -f
RewriteRule ^(.*) /offline.html [L]

For some reason this doesn't work. What am I missing here?

Upvotes: 2

Views: 2302

Answers (2)

anubhava
anubhava

Reputation: 784948

This condition will always fail:

RewriteCond offline.html -f

because -f needs full path of the file you are checking.

You can use %{DOCUMENT_ROOT} (Apache internal variable pointing to your website root) before filename you're checking to make a full path:

RewriteCond %{DOCUMENT_ROOT}/offline.html -f
RewriteRule ^ offline.html [L]

Upvotes: 2

Croises
Croises

Reputation: 18671

You can use:

RewriteCond %{DOCUMENT_ROOT}/offline.html -f
RewriteRule ^(.*) /offline.html [L]

Upvotes: 0

Related Questions