title: RewriteRule htaccess if a file exists
body: <p>I want to use htaccess to check if a file called offline.txt exists in the same directory as the htaccess file, if it exists then do:</p>
  
  <pre><code>RewriteRule ^.*$ /websiteOffline.php [L] 
  </code></pre>
  
  <p>and also have an exception to a certain range of ip addresses</p>
  
  <p>The idea is that if i want to take my entire site down for maintanance i could simply place a file called offline.txt and that would do it and allow certain ip's to bypass this condition.</p>
  
  <p>Any suggestions on how this can be acheived?</p>
  
  <p>Thanks</p>
  
  <p>i've tried the following code but doesnt seem to work:</p>
  
  <pre><code>RewriteEngine on
  RewriteCond /offline.txt -f
  RewriteRule  ^(.*)  /websiteOffline.php [L]
  </code></pre>
  
  <p><strong>update</strong></p>
  
  <p>Just used Jon's suggestion as folows:</p>
  
  <pre><code>RewriteEngine on
  RewriteCond %{DOCUMENT_ROOT}/offline.txt -f
  RewriteRule  ^(.*)  /websiteOffline.php [L]
  </code></pre>
  
  <p>Slight problem with this is that the file websiteOffline.php is in the folder where the rewritecond is applied so hence is not able to display that file. any suggestions</p>