Forum Moderators: phranque

Message Too Old, No Replies

redirection based on IP address

only let certain IP addresses into the site, all others redirected

         

lshannon

7:17 pm on Nov 29, 2004 (gmt 0)

10+ Year Member



Hello All;

I am new not only new to Apache but to webservers in general. This is about
to change.

Our site is using Tomcat 5.0.19 and Apache 1.3.27. These two communicate
using jk_mod 1.2 (currently researching what this is).

I have been given the task of setting up a maintenence mode feature for the
site.

This would be a script (I think it will be, maybe I am wrong) that would put the site into a
mode where only certain IP addresses would be able to access the main
content and all other would be redirected to an html page informing the user
the site is under maintenance.

I don't have a lot of time to do this so I need to be efficient.

Can someone give me a few terms or concepts I can use to focus my search? At present I
am looking at redirection with Apache ( Mod_alias ). Is this the right path
or is there something that already exists that could serve my needs?

I am guessing Perl will come into play? Is Python an option?

Thanks,

Luke

jdMorgan

9:34 pm on Nov 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> all other would be redirected to an html page informing the user the site is under maintenance.

Don't do this unless your site consists of user-modifiable data (like a forum). "Closed for maintenance" is a big red flag that can be read "Amateur site."

Instead, create two subdirectories on your server. Let's call them subdirectory 'A' and 'B'.
Then use mod_rewrite to point requests for your domain to subdirectory 'A'. Create and map a subdomain --let's call it 'test.yourdomain.com' to subdirectory 'B', and restrict access to a few IP addresses.

Now you can copy subdirectory 'A' to subdirectory 'B' and freely modify and test using your test subdomain. When you are satisfied that the changes are complete and correct, go back to the mod_rewrite code, and swap that 'A' and 'B' subdirectory mapping. Your domain's content will 'instantly' change to the new content, and you can now reverse the procedure above, copying subdirectory 'B' to 'A' and using 'A' to develop and test new content.

There are actually many ways to do this, but in most cases, it's not necessary to take your site down just to work on it.

There are indeed legitimate reasons why a site might need to be taken offline. One example is a site where a dynamic database must be shared across several servers because of server workload issues. In a case like that, it might be necessary to periodically 'synchronize' all the copies of the database, so that all changes on each server are propagated to all servers. But consider that Google does this quite often without taking their servers offline.

Jim

lshannon

10:09 pm on Nov 29, 2004 (gmt 0)

10+ Year Member



Thanks for the reply Jim. Your suggestion makes perfect sense. However, here is the background.

The site is a content management application. Management has specifically requested that with the flip of a switch (so to speak) only developers and testers would be able to access the site. Not totally sure why, but they tell me it is pretty valuable to them and they sign my checks.

I am experimenting with handling this with a Perl script that would be started when in maintenance mode and turned off when it is complete.

Not sure what else I can do.

Thanks,

Luke

Joe Belmaati

10:34 pm on Nov 29, 2004 (gmt 0)

10+ Year Member




Options +FollowSymLinks
RewriteEngine on

# These are the dev guys and they're ok
RewriteCond %{REMOTE_ADDR} !^(xx\.xx\.xx\.xx¦yy\.yy\.yy\.yy)
RewriteRule .* /pathto/maintenance.html


Jim is the rewrite expert, but I think this might work. Put it in your root-dir .htaccess file....remeber to replace the broken vertical pipe ¦ with a solid one. To switch off, simply add # in front of the two rewrite lines.