简体   繁体   中英

htaccess: redirecting traffic to maintenance page removes images from maintenance page

When I put my website in maintenance mode, I redirect all traffic to a notice.html webpage, except for traffic coming from my IP address (eg 111.111.111.111 below), by including the following lines in my .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/notice\.html$
RewriteRule ^(.*)$ https://www.mydomain.com/notice.html [R=307,L]

This seems to work well except for one issue -- if I include an image in the notice.html HTML code, such as

<img src="/path/to/myimage.png">

then this image file is no longer displayed (for IP addresses other than 111.111.111.111). If I comment out the above lines in my .htaccess file, then the image loads.

Any idea how I can whitelist the image file while I'm redirecting?

The image is no longer displayed, because the request for it gets rewritten to notice.html as well – and since that's not an actual image, but an HTML document, the browser will not display an image.

But since you already seem to know how to add an exception to your rewriting for that notice.html , you should just add another one for that particular image, so that it can be served even when your site is in maintenance mode.

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