SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess redirect and IP block

    how do I accomplish these two? I just can't seem to get it right... What I want to do is to just allow myself access to the site and redirect everyone else to the construction page (my site is under construction)

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

    Please specify what you want to redirect to ... or correct this generic code
    Code:
    RewriteEngine on
    RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
    RewriteRule .? http://www.example.com [L]
    This will only allow the localhost (127.0.0.1) to access the directory and all subdirectories but redirect everyone else to example.com - fill in the correct IP address and redirection.

    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

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry it took me so long to reply (situations in real life came up) anyway, I tried that code but it gave me "This webpage has a redirect loop" so what do you suggest?

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Why would you redirect? This seems like a perfect place to use Allow and Deny to me

    Code:
    Order Deny,Allow
    Deny from all
    Allow from yo.ur.i.p
    This will show the website when accessed from your IP, and show a "403 forbidden" page to everyone else

    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but my site is under construction right now, so I was wanting to show the visitors an under construction page.

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    In that case you might want to have a look at this, where your exact problem is described and solved
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what I'm doing wrong, cause it's still not working...

  8. #8
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    What code do you have now?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I have a feeling that I have the IP wrong now, but I'm using the IP that's mentioned at whatsmyip.org, but yet it redirects me?

  10. #10
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Yes that IP is the one you're using to visit your website -unless you have a really strange setup.

    What is the code you have now? Feel free to mask out your IP, i.e., w.x.y.z or something.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  11. #11
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I finally got the redirect working, but now my CSS and images aren't working, the CSS will work for the maintenance page, but images won't work on it. This is the code I'm using now:

    Code:
    # MAINTENANCE-PAGE REDIRECT
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{REMOTE_ADDR} !^this\.is\.my\.ip
     RewriteCond %{REQUEST_URI} !/construction.html$ [NC]
     RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
     RewriteRule .* /construction.html [R=302,L]
    </IfModule>
    I found this code off of htaccess Redirect to Maintenance Page

  12. #12
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    If you want css to work too you should modify it as follows

    Code:
    # MAINTENANCE-PAGE REDIRECT
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{REMOTE_ADDR} !^this\.is\.my\.ip
     RewriteCond %{REQUEST_URI} !/construction.html$ [NC]
     RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css)$ [NC]
     RewriteRule .* /construction.html [R=302,L]
    </IfModule>
    Also, you can get rid of the <IfModule mod_rewrite.c> and </IfModule> once you've established mod_rewrite is installed and working, no need to ask that again and again
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  13. #13
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well it finally works now but now I have another question, it's concerning the redirect from earlier, i found out why I had such trouble from it, because I was testing it on another computer from within my house, and once I tried it on a proxy site, the redirect worked, I then realized that all of the computers in my house share the same public IP but just different LAN IPs, but I tried using my LAN IP in the .htaccess file, and it redirected me (which is not what I want), so how can I redirect all the computers in the house and everybody else in the world? (though I already accomplished the everybody in the world part lol)

  14. #14
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    It's the public IP that you should filter. The internal LAN IP shouldn't match at all (because that's hidden behind NAT). Are you saying it does?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  15. #15
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I'm saying that the other computers in the house have the same public IP according to whatsmyip.org so their not getting redirected like I would want them to.

  16. #16
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Ah okay. Yes, you can't do that. Have you considered installing a web server on your own PC for development purposes? That's also nicer because it's all local and thus faster and you don't have to upload files all the time
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  17. #17
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually that's what I've been doing for some time now, I just uploaded the files to make sure everything would run smoothly once I got the website running (though I've still got a long way to go lol)

  18. #18
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Although I'm a day late and a dollar short, the way I do it is to use DirectoryIndex public_link private_link so that the public only see the public link (index.html) while I link directly to the private_link (index.php). That way, I can have visitors see the "under construction" notice while I can see (and provide links for my clients) the "work in progress."

    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
  •