503 redirect across multiple Urls with the exception of one

Asked

Viewed 526 times

7

How to make a 503 redirect (maintenance code) throughout the site, but leave only one URL with access?

Server: Linux (Apache) with PHP 5.5 and Mysql.

  • Linux Server (Apache) - PHP 5.5 and Mysql.

1 answer

8


Put in the .htaccess (or apache configuration):

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/caminho/permitido.html
RewriteRule .* /erro503.php

To ! in the RewriteCond means denial, i.e., the condition is that the path nay is indicated below, so that the RewriteRule take action.

This is the script erro503.php:

<?php
   header('HTTP/1.1 503 Service Temporarily Unavailable');
   header('Status: 503 Service Temporarily Unavailable');
   header('Retry-After: 3600');
?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
   <title>Servi&ccedil;o Temporariamente Indispon&iacute;vel</title>
</head><body>
   <h1>Servi&ccedil;o Temporariamente Indispon&iacute;vel</h1>
   <p>(Ponha sua explicacao aqui).</p>
</body></html>
  • change the value of Retry-After for the desired time in seconds (pro-form, in practice I think no agent uses that value)

  • the header Status only if you use PHP as CGI.

  • Got Bacco. In case then allowed.html will be the only accessible, correct?

  • 2

    Exactly. Test and tell the result, if we need to adjust.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.