0

I am trying to set up a maintenance mode using .htaccess, which allows a user visiting from a certain IP to still view the site. The site is running from a CMS (Perch Runway) which uses rewrite rules as part of the system, so these would need to be working for the visitor from that IP. The Perch Runway code is this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/perch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /admin/core/runway/start.php [L]

My redirect maintenance code is this:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

I have tried combining the two but am getting a redirect loop. So in short I need to have:

  • Maintenance mode redirect to maintenance.html
  • Person visiting from IP 11.111.111.111 does not get affected by this redirect
  • Person visiting from IP 11.111.111.111 still gets affected by Perch Runway redirects

Please note I want to show the maintenance.html page to those not visiting from the specified IP, so can't use deny.

Help greatly appreciated!

Mike Harrison
  • 1,020
  • 2
  • 15
  • 42
  • Possible duplicate of [Deny all, allow only one IP through htaccess](http://stackoverflow.com/questions/4400154/deny-all-allow-only-one-ip-through-htaccess) –  Mar 09 '16 at 13:12
  • I have looked at this and it uses `deny`, rather than redirecting to a specified page. I need to redirect those visitors not from the specified IP to the `maintenance.html` page, not completely deny access. – Mike Harrison Mar 09 '16 at 14:30
  • [This answer](http://stackoverflow.com/a/10653671/5925366) for the same question does exactly what you want to achieve. Not tested, but I believe many people have been through it and it worked. –  Mar 09 '16 at 14:35

1 Answers1

0

In combination with answer which was posted in comment, I tested this on a Wordpress page and it works:

ErrorDocument 403 /liesmich.html
order deny,allow
deny from all
allow from 111.222.333.444
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

So for Perch Runway would look something like this I bet:

ErrorDocument 403 /maintenance.html
order deny,allow
deny from all
allow from 111.222.333.444
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/perch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /admin/core/runway/start.php [L]

Posting an answer from comments because new lines are being cut off and code looks terrible.