0

My application is fully built now. But at times i need to bring it down for maintenance. So i created a .htaccess file and now when users try to open the application they get redirected to a different page with a maintenance image in it. The problem is after the superadmins are done with the maintenance, they need to check if the app is working fine now. But there is no way to do that as even they get navigated to the maintenance page. One of the solution is to create a testing environment. But is their any other easy solution ?

hakre
  • 193,403
  • 52
  • 435
  • 836
Abhishek Saha
  • 2,564
  • 1
  • 19
  • 29
  • In your case the live environment is the test environment. Allow access from certain points not seeing any maintenance message. As you said .htaccess start with Apache httpd access control. – hakre Oct 29 '12 at 13:24
  • Dont do it in htaccess, have a site setting like online/offline. then redirect accordingly, but dont have a redirect when the route is admin login. – Lawrence Cherone Oct 29 '12 at 13:25
  • This is not a question but a google request I'd say: http://davidwalsh.name/htaccess-maintenance-page-redirect – hakre Oct 29 '12 at 13:26
  • "Allow access from certain points" - This is exactly what i want. But is this possible only through .htaccess ? – Abhishek Saha Oct 29 '12 at 13:26
  • @AbhishekSaha: Depends on the webserver configuration, the application iteself, your needs etc.. Btw. the way you ask this question is not very constructive because there are a thousand ways how to do that. – hakre Oct 29 '12 at 13:27
  • @LawrenceCherone, i cant have a online/offline switch because the user cant even login. before that only he gets redirected. – Abhishek Saha Oct 29 '12 at 13:27
  • Again: That depends on *how* you do that. If you first create the situation that *it is not possible* then *it is not possible*. See the link earlier which might give you an idea. Instead of IP adresses, cookies work too and there is a full layer of dedicated access control with apache. – hakre Oct 29 '12 at 13:29
  • @hakre, i posted this in SO to get one of the feasible answer which can be easily done. – Abhishek Saha Oct 29 '12 at 13:29
  • Then have something like `RewriteCond %{REQUEST_URI} !^/admin_login$` lol – Lawrence Cherone Oct 29 '12 at 13:29
  • Possible Duplicate of: [How to implement “Maintenance Mode” on already established website](http://stackoverflow.com/q/1396848/367456) – hakre Oct 29 '12 at 13:35
  • How can it be a duplicate when i told you even login page gets blocked. – Abhishek Saha Oct 29 '12 at 13:37
  • @AbhishekSaha: Well I wonder why you accepted the answer then. It's exactly the same. – hakre Oct 29 '12 at 14:56
  • @hakre - I came here to get an idea, a logic. I decided to do this in the following way. When the superadmin tries to deactivate the site, his action will create .htaccess file with his current ip, so that he can view. At this time, no users, no other superadmins will be able to view. I realized other superadmins are actually not needed to view the site. After the maintenance his done, he again toggles the maintenance mode which deletes the .htaccess file. His answer didnt give a complete code which i never asked but gave me the idea. – Abhishek Saha Oct 29 '12 at 15:37
  • @hakre - Your reputation is a proof that you are knowledgeable. No doubt in that. But you are really not humble to your juniors. Your activities in this post was only sarcastic comments. I didnt post .htaccess code because i really dont need help in coding. I was looking for a good, easy and feasible logic. – Abhishek Saha Oct 29 '12 at 15:41
  • And your comments didnt change my thoughts for you. You are still someone i respect and will always look out for interesting solutions from your end. Cheers. – Abhishek Saha Oct 29 '12 at 15:43
  • @AbhishekSaha: Please read the [FAQ](http://stackoverflow.com/faq) and [ask advice](http://stackoverflow.com/questions/ask-advice) again. Then you might better understand why these kind of questions are problematic. If you have a free floating issue and you're looking for opinions, join in the [PHP chat](http://chat.stackoverflow.com/rooms/11/php). There you can better discuss various things around ideas and such. – hakre Oct 29 '12 at 15:43
  • @hakre if You would have posted this comment in the beginning i would have immediately joined the chat. You know this community better. But the way you commented was not the proper way to guide. – Abhishek Saha Oct 29 '12 at 15:45

1 Answers1

3

If you have some Static IP's in the .htaccess file you can try doing:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

Ypu can specify several REMOTE_ADDR lines for more than 1 'admin' ip if needed.

This will send anyone with IP's NOT mentioned to the maintenance page.

An ALTERNATIVE is to handle the maintenance mode within PHP... basically then you can have a list of IP's in a php script and show maintanance page or run app as normal... obviously such solution would need to be properly placed in the flow of you're code and some simple mechanism to enable/disable the site.

Brian
  • 8,418
  • 2
  • 25
  • 32
  • @hakre, gave me this link. And the situation is very similar to mine. The only difference is that we have multiple superadmins who can access from different locations. – Abhishek Saha Oct 29 '12 at 13:32
  • You just add more %{REMOTE_ADDR} lines for whatever IP's they have. – Brian Oct 29 '12 at 13:33
  • @AbhishekSaha: That's unfair. Now that there is an answer, you start to elaborate the question. That is *not constructive*. – hakre Oct 29 '12 at 13:33
  • And i also think that this is the most feasible solution. I will wait for some more answers, else will accept your solution. Thanks. – Abhishek Saha Oct 29 '12 at 13:34
  • @hakre, i am sorry about that. I am not denying any solution. I am just looking for options. – Abhishek Saha Oct 29 '12 at 13:35
  • And that is exactly part of the problem. Please make yourself more comfortable how this website works. It's not only about you, but about future users and those that answer, too. See your question, it has no technical information at all. You didn't even post your .htaccess snippet so far. – hakre Oct 29 '12 at 13:36
  • @hakre, i respect your knowledge and dont consider myself in a state to argue or say sorry multiple times. If you have understood the question, why not edit it a bit and format in a better way. I will learn that way. Your comments are not helping. – Abhishek Saha Oct 29 '12 at 13:39
  • @AbhishekSaha: I can not post *your* `.htaccess` snippet, because I do not have it. – hakre Oct 29 '12 at 13:40
  • @Brian, i read your alternate. I am thinking if it has any flaws. – Abhishek Saha Oct 29 '12 at 13:42
  • @hakre, i had posted a question earlier regarding the htaccess file and i got help from people. Here is the posted question - http://stackoverflow.com/questions/12210881/htaccess-to-allow-one-file-and-one-folder-to-be-accessed – Abhishek Saha Oct 29 '12 at 13:43
  • .htacess is simple. It just diverts all people to mainteinance page. – Abhishek Saha Oct 29 '12 at 13:44
  • @Brian. The alternate solution looks fine. I have the header file which is common for all other files. I can place my ip array in the header file and it will do the work. Great !! Now, which way do you recommend ? – Abhishek Saha Oct 29 '12 at 13:56
  • 1
    That's purely down to you're preference... PHP - way means you can turn site on/off via the admin site itself, as well as quickly add IP's (if you store in do or could write and parse some text file when checking ips). .htaccess way works very well too... but requires editing at server side when you need to enable/disable sites and add/remove IPs ... so just whatever is going to be easiest for you're organisation/site to do! – Brian Oct 29 '12 at 13:58