简体   繁体   中英

htaccess code for maintenance page redirect

I set up a maintenance page that I could enable through an htaccess file. The html file is located in a folder called "maintenance".

The html file has some images in it. However, visitors to the page see no images, even though I added a RewriteCond line to (theoretically) allow them.

If I try to visit the URL of an image file in the browser directly, it redirects to the maintenance.htm page. I do not want image files to be redirected.

Am I missing something?

#RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
#RewriteCond %{REMOTE_ADDR} !^111.111.111.111$
RewriteCond %{REQUEST_URI} !/maintenance/maintenance\.htm$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif|css|ico)$ [NC]
RewriteRule ^(.*)$ /maintenance/maintenance.htm [R=302,L]

I think this will work:

<IfModule mod_rewrite.c>
  RewriteEngine on
  # RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
  # RewriteCond %{REMOTE_ADDR} !^111.111.111.111$
  RewriteCond %{REQUEST_URI} !/maintenance/maintenance\.htm$ 
  RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif|css|ico)$ 
  RewriteRule ^(.*)$  /maintenance/maintenance.htm [L]
</IfModule>

I added a condition to confirm the rewrite module is active before procesing the rule. The question rule and conditions are not modified.

This rule was tested here .

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