I have to put a site down for about half an hour while we put a second server in place. Using .htaccess, how can I redirect ANY request to domain.com
to domain.com/holding_page.php
?
3 Answers
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/holding_page.php$
RewriteRule $ /holding_page.php$l [R=307,L]
Use 307 (thanks Piskvor!) rather than 302 - 307 means:
The requested resource resides temporarily under a different URI. Since the redirection MAY be altered on occasion, the client SHOULD continue to use the Request-URI for future requests.

- 1
- 1

- 97,747
- 36
- 197
- 212
-
This seems to work RewriteEngine on RewriteCond %{REQUEST_URI} !/indexTEMP.php$ RewriteRule $ /indexTEMP.php [R=307,L] – stef Mar 03 '10 at 14:28
-
2As this answer still comes up top in search results, it might be a good idea to add `RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]`. This stops images breaking through redirecting them to the holding page. I know it wasn't strictly part of the original question - but handy nonetheless. – Dave Dec 07 '14 at 11:53
As I came across this problem, here is the solution I used (brief explanations in the comments):
RewriteEngine On
RewriteBase /
# do not redirect when using your IP if necessary
# edit to match your IP
RewriteCond %{REMOTE_ADDR} !^1\.1\.1\.1
# do not redirect certain file types if necessary
# edit to match the file types needed
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css)
# this holding page that will be shown while offline
RewriteCond %{REQUEST_URI} !^/offline\.html$
# use 503 redirect code during the maintenance job
RewriteRule ^(.*)$ /offline.html [R=503,L]
ErrorDocument 503 /offline.html
# bots should retry accessing your page after x seconds
# edit to match your maintenance window
Header always set Retry-After "3600"
# disable caching
Header Set Cache-Control "max-age=0, no-cache, no-store"
Besides the additional conditions and headers, the main idea is to use a 503
status code when you are doing a maintenance job.
The 503
code stands for Service Unavailable
, which is exactly the case during the maintenance. Using this will also be SEO friendly as the bots won't index the 503
pages, and they will come back later-on after the specified Retry-After
to look for the actual content.
Read more details here:
- Use a 503 HTTP status code (from a person who worked at Google) - https://plus.google.com/+PierreFar/posts/Gas8vjZ5fmB
- Redirect Site to Maintenance Page using Apache and HTAccess - http://www.shellhacks.com/en/Redirect-Site-to-Maintenance-Page-using-Apache-and-HTAccess
- HTTP 503: Handling site maintenance correctly for SEO - https://yoast.com/http-503-site-maintenance-seo/

- 354
- 4
- 13
This works better...
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/holding_page.php$
RewriteRule $ /holding_page.php [R=307,L]

- 69
- 3
- 5