503 Forwarding on multiple URLs except for one

7

How to make a redirect 503 (maintenance code) on every site, but leave only one URL that can be accessed?

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

    
asked by anonymous 15.04.2014 / 18:38

1 answer

8

Put in .htaccess (or apache configuration):

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

The ! no RewriteCond means deny, that is, the condition is that the path is not indicated below, so that RewriteRule takes 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 to the desired time in seconds (pro forma, in practice I think that agent does not use this value)

  • header Status is only required if you use PHP as CGI.

15.04.2014 / 18:52