简体   繁体   中英

.htaccess maintenance mode rewrite

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM