Redirect "Almost" All IPs to a Static HTML Page

Hi guys,
I realize this isn't a WPMU Dev (or even a WPMU) question, but I'm hoping someone more familiar with PHP or htaccess can help me out.

I have a WordPress site in development (mysite.com). Although the site is in development, having it "online" makes it easier to collaborate with others who are working on the project with me from different locations. We're ready to start doing some early promotion and have created a temporarily static page at (mysite.com/index.html) to capture leads, provide basic info, etc. I'd like to use either php (in the generic WordPress index.php file perhaps) or the htaccess file to redirect all visitors who's IP addresses do not appear on a short list.

If this were just a logical statement, it would be "If IP address is not IP1, IP2 or IP3, redirect to mysite.com/index.html, else view the site normally". What would be the simplest way to achieve this goal?

Thanks

  • aecnu
    • WP Unicorn

    Greetings nycwebworks,

    Thank you for this great question and a significant item to bring up.

    It is my opinion that htaccess is the way to go on this one:

    ErrorDocument 403 http://www.domain.com
    Order deny,allow
    Deny from all
    Allow from 123.124.61.67
    Allow from 95.44.8.129

    The http://www.domain.com is where to redirect them to if they are not one of the IP's in the allow from lines.

    Thank you for being a WPMU Dev Community Member!

    Cheers, Joe

  • NYCWW
    • Site Builder, Child of Zeus

    Thanks Joe... Unfortunately, that code is not working and I'm getting the following error:
    Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

    I believe this is because the static page I am trying to redirect to is on the same domain and the redirection of invalid IPs is at the domain level. Therefore each time I redirect to the static page, it checks to see if the IP address is allowed and tries to redirect to the static page again. It's an endless loop.

    Is there a way to only exclude my static URL from the IP?

  • NYCWW
    • Site Builder, Child of Zeus

    OK, I've come up with a workaround that involves two plugins (although they're plugins I'd be using anyway, so there is no additional overhead).

    First, I installed the Redirection plugin and set up a temporary redirect that sends users who are not logged in to my static "coming soon" page. Logged in users are not redirected at all.

    The problem with this method is that the redirect is page specific, so a visitor, bot, etc., would be redirected if they visited my homepage but would NOT be redirected if they stumbled across any other page (including a 404 page).

    I was able to close the back door using your Multisite Privacy plugin to set access to "admin only".

    Now if a user visits my homepage and they are not logged in, they'll be redirected to a temporary "mini-site". If they visit any other page, they'll be redirected to my login page. Best of all, my collaborators can still access the website by visiting my login page directly!

    You can see it in effect here.

    I hope this helps someone else trying to achieve a similar result.

  • aecnu
    • WP Unicorn

    Greetings nycwebworks,

    Thank you for your additional input, it is greatly appreciated of course.

    You are absolutely correct that my coding will not work for those wanting to redirect to a URL on the same TLD and if the same TLD is indeed used it will cause an endless redirect loop.

    Therefore to use this code successfully the redirect page should be on a different domain to avoid the loop.

    I should have mentioned this but I did not consider a redirect to the same TLD and therefore my bad. Otherwise it works flawlessly and efficiently :slight_smile:

    Cheers, Joe

  • aecnu
    • WP Unicorn

    Greetings rohmann,

    Thank you for letting me know, I really appreciate it.

    Stay tuned because I believe that there will be many useful and interesting more htaccess tips and tricks coming in an article I am writing about on that very subject.

    Thanks again and thank you for being a WPMU Dev Community Member!

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.