Yii 1.1: underconstruction

redirect users to a under construction (or nothing) page by IP Address.

I wanted the option of hiding my yii application from the public, and .htaccess did not 100% serve my needs. Using this component, I can very easily turn my site on and off and add manage allowed IPs from my config file.

I mainly use this as a way of protecting a site from the general public during development/testing/etc, redirecting the user to a 'coming soon' page.

ALSO: i'm a bit of a noob and wasn't sure how this should be categorized/tagged. Please post suggestions if you have them.


...requirements of using this extension (e.g. Yii 1.1 or above)...




...how to use this extension...

  1. Upload file UnderConstruction.php to components directory
  2. Load Component in main.php
// preloading 'log' component
  1. Configure Component
'UnderConstruction' => array(
            'class' => 'application.components.UnderConstruction',
            'allowedIPs'=>array('',''), //whatever IPs you want to allow
        'locked'=>true,//this is the on off switch
            'redirectURL'=>'http://www.yiiframework.com',//put in your desired redirect page.           

Total 6 comments

#14632 report it
Szymon Dudziak at 2013/08/30 01:14pm
Redirection loop solved

Hi, If someone has issue with redirection loop, this is the simple solution. Under /components/UnderConstruction.php add one if() statement like following, to detect current URI:

if ($allowed) { /*do some important thing like ... nothing */ } 
else {
   if ($_SERVER['SCRIPT_URI'] !== $this->redirectURL) {

Simple, and it works. Regards

#14274 report it
leo4all at 2013/07/31 04:48pm
static page

What if I want to send user to static page instead of another website.

Got redirect loop if tried to do so.

#7719 report it
dmapes123 at 2012/04/11 09:48am

I appreciate the suggestions and whole heartedly agree with you on the value of testing verses production environments and source control deployments. I also use git (via github.com), but unfortunately I haven't yet gotten the more advanced features figured out, its basically just a online repository/backup for me at this point. I will though.

One of the things I really like about yii is the ability to build out a proof of concept MVP (Minimum Viable Product) very quickly, and prior to that MVP launch, I only would have one environment. Hopefully in the future some of my apps will be successful enough to demand a more professional way of operating.

Regarding the ajax requests...I presume since the site is deactivated everywhere that none of the site built requests would be available, and as such wouldn't be needed. Obviously that is not the case if you're running web service API, but in that case this probably wouldn't be the best idea for you.

Thanks again.

#7709 report it
Vitalets at 2012/04/11 04:20am

Hi duncanmapes

it's really good that you are sharing your code for that. I think standart catchAllRequest is not flexible enough and should be extended.

  1. Access by ip is helpfull. (but also I suggest to setup test and production environments and do not make many changes on live site manually. Use version control instead, e.g. git:))

  2. I'll explain what I mean: I have empty file maintenance.txt in webroot folder. If I want to toggle site to construction mode, I can do it very fast and easy via renaming file to maintenance123.txt or any other name. My code in config checks for file and toggles mode:

'catchAllRequest' => (file_exists(dirname(__FILE__).'/../../../maintenance.txt')) ? array('maintenance/index'): null,

But if I change "locked" property straight in code, I need to make extra commit and deploy every time I need maintenance. Not very convenient. It would be nice to build-in such feature in you component.

  • And one more issue I faced:
    imagine user performs Ajax request when you enabled construction mode. What will he get? He will not be redirected and may be will not understand what happens at all =)
    It would be cool to process such case also.


#7699 report it
dmapes123 at 2012/04/10 10:39am

@vitalets thanks for the questions.

  1. I have to be honest I was unaware of catchAllRequest prior to building this little component, but from looking it over it doesn't appear that it would have served my purposes anyway, because it locks out the entire site, I want to lockout the site only to the general public but allow myself or other developers/testers/etc to access the site. IP addresses seem like the easiest way to do that.

  2. I'm not sure how renaming a directory would help anything other than prevent access to the entire application, which isn't what I was going for.

I understand this may be a narrow solution to a very specific issue, but it was sort of a pain for me to deal with, and I have benefited greatly from some of the extensions provided by the community here and just wanted to try and contribute.

#7691 report it
Vitalets at 2012/04/10 01:38am


  1. what are the benefits of this extension against catchAllRequest ?

  2. for me more usefull to toggle construction/normal mode by renaiming empty file in root directory. Otherwise I need to change config and deploy project each time! It would be nice to have such option in extension.

Leave a comment

Please to leave your comment.

Create extension