SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Florida
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Allowing certain IPs to view site and redirecting everyone else using htaccess?

    I'm not sure if a .htaccess file is the right way to go, but I'm about to preform a big upgrade on one of my sites and I would like to redirect ALL my traffic to a specific file that will show them a "site is down" message. The tricky part is allowing a list of IP's access to the site during this time. Is this possible with a .htaccess file or should I seek an alternatives method?

  2. #2
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A simple

    deny from all
    allow from <insert ip's>

    would do the trick i suppose?

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Ken,

    RK's suggestion is good except that it doesn't take care of the redirection.

    With mod_rewrite (.htaccess), you can do this with a series of RewriteCond statements (NOT IP#1, NOT IP#2, etc) then allow the Rewrite Rule to redirect all to your placeholder page. You may want to make this redirection ONLY for pages, i.e., not images, css, js, etc.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I need to do this too. My site is under construction, so I need to redirect everybody to an "Under Contruction" page while allowing my IP address to see the site.

    dklynn - Can you write this out for me? Regular expressions and mod_rewrite tend to melt my brain.

    Thanks, Sandra

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    CF,

    That's a "script kiddie" request. I would have preferred that you make an attempt, first!
    Code:
    RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$
    RewriteCond %{REMOTE_ADDR} !^124\.124\.124\.124$
    # these are ANDed automatically
    RewriteRule \.(php|htm.?)$ /site_is_down.php [R=302,L]
    # R=302 is a temporary redirect
    Obviously, you will have to correct the list of Remote Addresses.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •