Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporary redirect to maintenance page

I am trying to write a rule to redirect all URLs to a temporary page so that some site updation could be done, but it ends up in an infinite loop.

  RewriteCond %{HTTP_HOST} ^(.*)mysite\.com$
  RewriteCond %{REQUEST_URI} !^(.*)temp$
  RewriteRule ^(.*)$ http://www.mysite.com/temp [R=307,L]

How to check if it's a temp page?

like image 762
user88975 Avatar asked Feb 02 '23 12:02

user88975


2 Answers

You need to write rule for all request except maintenance file.

.htaccess should be:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]
like image 51
Nimit Dudani Avatar answered Feb 15 '23 20:02

Nimit Dudani


What I do is to redirect all traffic to a maintenance.html page when it's not coming from my IP.

The first rewrite condition avoids an infinite loop.

RewriteCond %{REQUEST_URI} !/maintenance.html$ 
RewriteCond %{REMOTE_ADDR} !^172\.16\.254\.1$
RewriteRule $ /maintenance.html [R=302,L] 
like image 39
Chris Aelbrecht Avatar answered Feb 15 '23 22:02

Chris Aelbrecht