Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a folder called "coming-soon" that I would like to redirect all traffic to when the site is down for maintenance.

Currently, this is what I did:

----- START -----

location / {

allow 123.456.789;

deny all;

page_error 403 coming-soon/index.php;

}

location /coming-soon {

allow all;

}

----- END -----

The problem is, if someone tries to access a sub-folder (e.g. /blog), it will not redirect to Coming Soon folder.

Can someone please help? Thanks in advance!

share|improve this question
    
What is the rest of your server configuration? –  Michael Hampton Jun 11 '13 at 17:55
add comment

1 Answer

location /coming-soon {
   #empty block
}
location / {
    if ($remote_addr != 123.456.789) {
       rewrite ^ /coming-soon/index.php last;
    }
}

http://stackoverflow.com/questions/16553980/nginx-redirect-without-rewriting-the-url-excluding-ip-and-directory

share|improve this answer
    
Thank you, @eisaacson. It works, but only for "/". I can still view "/blog". The redirection works only for the root directory? By the way, I have another location directive specified for "/blog". Could that be the reason why its not working? I thought the "last" parameter would have prevented Nginx from evaluating other location directives? –  Honey Badger Jun 12 '13 at 0:21
    
Another problem: Assets (such as images) also failed to load in Coming Soon page. –  Honey Badger Jun 12 '13 at 0:42
    
@HoneyBadger Yes, having a location block for /blog will override the / block for that directory. Is your /blog block before the / block? –  eisaacson Jun 12 '13 at 18:17
    
@HoneyBadger If you are trying to load assets from other directories than /coming-soon, they will be redirected just like everything else. I did a similar thing recently but I just made my '/coming-soon' directory completely independent, having all the assets inside of it. –  eisaacson Jun 12 '13 at 18:52
    
@HoneyBadger Did you get this to work? –  eisaacson Jun 19 '13 at 20:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.