SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: .htaccess

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

    .htaccess

    Not sure if this is the correct throead to post this but, how can I go about and changing my .htaccess to where only I would see a certain page, and everyone else is redirected to another page?

  2. #2
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    20,288
    Mentioned
    225 Post(s)
    Tagged
    3 Thread(s)
    Off Topic:

    Thread moved to Server forum.


    This may be a display of total ignorance on my part, but the one way I sort of know to do that would be to put a .htaccess file inside the folder you don't want people to see, and insert code something like this:

    Code:
    ErrorDocument 403 /redirect-folder/ 
    Order deny,allow 
    Deny from all 
    Allow from 111.222.333.444
    So, /redirect-folder/ would be the folder you redirect everyone to, and the bit in red is your own IP address.

    This is not my area, though, so I may get shot down for this! But I can take it. I'm happy to learn. This will only suit you if the page you don't want people to see is in a folder of its own, too. I'm sure there will be other solutions if you need something else. Maybe even PHP would be the way to go.
    Last edited by ralph.m; Apr 30, 2012 at 02:10.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Try your hand at the new JavaScript Challenge!

    If you don't like getting your feet stuck in a bog, avoid Twitter BootsTrap.

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

    I think you've got a start on the correct answer (wouldn't you have to specify the <Files>?) but offer my initial thought about using mod_rewrite (surprise, eh?):
    Code:
    RewriteEngine on
    # Identify yourself via some Apache variable like
    RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.2$
    RewriteRule ^private_regex$ alt.page [R=301,L]
    # Remove the R=301, after testing to hide the redirection
    Of course, you can use any Apache variable to identify yourself to mod_rewrite (the {REMOTE_ADDR} will match your accessing IP address) and you'll need to identify the private and alt pages and use the correct regex for private and actual URI (relative to the DocumentRoot if this .htaccess is in the DocumentRoot). I've suggested the R=301 flag so you can see the redirection during testing but you should remove it so visitors will not be aware of the redirection.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated 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
  •