+ Reply to Thread
Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By ah-blabla
  • 1 Post By playminigames

Thread: Use .htaccess to redirect everyone except you

  1. #1
    ah-blabla's Avatar
    ah-blabla is offline x10 Lieutenant ah-blabla is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    375

    Use .htaccess to redirect everyone except you

    If you are currently working on a site, say at a subdomain sub.example.com, and would like to have all traffic going there redirected to example.com/page.html, but you still want to be able to access sub.example.com, you can use these htaccess commands:

    Code:
    # Where you want to redirect to
    ErrorDocument 403 http://example.com/page.html
    order deny,allow
    # You want everyone blocked
    deny from all
    # Except for your IP (replace with your IP)
    allow from 60.118.156.100
    This is useful e.g. when you are constructing a site and have already started advertising the address, but don't want it visible to anyone except yourself.

    Note: this is a made up IP in the code. Also, dydns domains don't work, since Apache uses reverse lookup to find the domain, so your PTR records must be correct if you're using a domain.
    Last edited by ah-blabla; 09-24-2009 at 11:39 AM.
    karimirt47 likes this.

  2. #2
    ichwar's Avatar
    ichwar is offline Community Advocate ichwar is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    NC, USA
    Posts
    1,454

    Re: Use .htaccess to redirect everyone except you

    This is helpful to know.

    I do have one question, since we turn of the modem every night to conserve power, each day I have a different IP. Is there any way to work around this so that I don't have to update my .htaccess every day?

  3. #3
    djalam is offline x10Hosting Member djalam is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    70

    Re: Use .htaccess to redirect everyone except you

    hey ah-blabla, since u seem to be knowledgeable about .htaccess, can you tell me how to make a custom 404 page to redirect to for my html website?

  4. #4
    playminigames is offline x10 Sophmore playminigames is an unknown quantity at this point
    Join Date
    Jul 2009
    Location
    earth
    Posts
    216

    Re: Use .htaccess to redirect everyone except you

    djalam to make a custom 404 page to redirect for your website should be

    ErrorDocument 404 YOUR URL HERE

    ex: ErrorDocument 404 /error/404.html

    Good Luck djalam!
    dinomirt96 likes this.

  5. #5
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,410

    Re: Use .htaccess to redirect everyone except you

    If you have a dynamic IP, it would be better off having a user/pass required to view the site except for one page, that basically tells you that the site is in construction.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  6. #6
    ah-blabla's Avatar
    ah-blabla is offline x10 Lieutenant ah-blabla is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    375

    Re: Use .htaccess to redirect everyone except you

    The other option with dynamic IP is to set up dyndns for your router (or for your pc if the router can't), and then redirect in php, e.g you add in the code:
    PHP Code:
    <?php
    if (($_SERVER['REMOTE_ADDR'])!=gethostbyname("dyndnsaddress.dyndns.org"))
    {
    header'Location: http://newadress.com/bla' ) ;
    }
    ?>
    This would have to be right at the beginning of whatever php file is loaded when visitors view the page.
    Another option with dyndns is to have a crons script which every 10 - 30 mins checks what the IP address is for your dyndns address, and then modifies the .htaccess file accordingly.

    The problem with Apache is it does a reverse lookup, which will fail for a dynamic dns. One possibility is to write an authentication module for apache doing a dyndns check, or to modify the mod_auth module in apache. (I might try this in the future, but I doubt X10hosting would use any old random patch I send in... You'd have to wait until the patch is accepted upstream which could take a while.)
    Last edited by ah-blabla; 10-14-2009 at 06:05 AM.

+ Reply to Thread

Similar Threads

  1. .htaccess redirect with regular expressions
    By Scoochi2 in forum Programming Help
    Replies: 0
    Last Post: 08-25-2008, 08:07 AM
  2. .htaccess 301 redirect help
    By skeets in forum Programming Help
    Replies: 6
    Last Post: 05-04-2008, 09:00 PM
  3. Redirect
    By BlueIce in forum Free Hosting
    Replies: 3
    Last Post: 10-21-2007, 09:06 AM
  4. default .htaccess
    By Fedlerner in forum Computers & Technology
    Replies: 9
    Last Post: 09-05-2007, 10:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers