+ Reply to Thread
Results 1 to 7 of 7

Thread: htaccess question

  1. #1
    lydia09 is offline x10Hosting Member lydia09 is an unknown quantity at this point
    Join Date
    Dec 2009
    Posts
    62

    htaccess question

    Hi everybody,
    I've created a subdomain on my web site, which I plan to put pages in, but I don't want to make that subdomain public for a while, so for the moment, I'd like to block access to the subdomain from all IP addresses except mine with a temporary redirect to a placeholder file in the document root of the subdomain.

    I thought .htaccess was the way to do it, and I made up this file in the document root of my subdomain:

    Options -Indexes
    RewriteEngine on
    RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
    RewriteRule http://subdomain.maindomain.x10hosting.com/* http://subdomain.maindomain.x10hosting.com/index.html [R=302,L]

    Unfortunately, the redirect doesn't seem to be happening; the files seem to be accessed as normal. Is .htaccess the right way to do this, and if so, what am I doing wrong? I've tried Googling, and this seems right, but clearly it isn't. Can anyone give me a hand, please?

    Thanks,
    Lydia

  2. #2
    Awesomexr's Avatar
    Awesomexr is offline x10 Sophmore Awesomexr is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    haslam.pcriot.com
    Posts
    118

    Re: htaccess question

    You can do this in cPanel, go to "Subdomains" and then click "Manage redirection" next to the subdomain you wish to redirect.
    Last edited by Awesomexr; 12-23-2009 at 09:16 AM.

  3. #3
    misson is offline Community Advocate misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,391

    Re: htaccess question

    If the subdomain maps to a subdirectory of public_html, the simplest way is to use:
    Code:
    Order Deny, Allow
    Deny from all
    Allow from XXX.XXX.XXX.XXX
    though that won't give you a redirect.

    As for RewriteRule, you can't match the URL scheme, host or query string in the pattern; you can only match against the path portion of the URL. Instead, you'll need to check the server name in another RewriteCond. Also, %{REMOTE_HOST} is the remote hostname, not IP. You'll most likely want to use REMOTE_ADDR.

    Code:
    RewriteCond %{REMOTE_ADDR} !=XXX.XXX.XXX
    RewriteCond %{SERVER_NAME} ^subdomain\.
    RewriteRule . /index.html [R=302,L]
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,267

    Re: htaccess question


    Code:
    RewriteCond %{REMOTE_ADDR} !=XXX.XXX.XXX
    RewriteCond %{SERVER_NAME} ^subdomain\.
    RewriteRule . /index.html [R=302,L]
    Doesn't the Redirect directive give you a loop?

  5. #5
    lydia09 is offline x10Hosting Member lydia09 is an unknown quantity at this point
    Join Date
    Dec 2009
    Posts
    62

    Re: htaccess question

    Thanks misson,
    That works well, I appreciate the help. Now, this seems right too, but I'd just like to double-check so I know I understand-- if I was just doing a temporary redirect for a folder and its contents (if the page I wanted to redirect to was in that folder), without worrying about a subdomain, it would be:

    Code:
     
    RewriteCond %{REMOTE_ADDR} !=XXX.XXX.XXX
    RewriteRule . index.html [R=302,L]
    right?

    Thanks,
    Lydia

    PS. Awesomexr, thanks for the advice, but that isn't quite the redirect type I want, I don't want to redirect everything, just everything except my IP.
    PPS. descalzo, I haven't run into a loop, where have you run into one, just as an FYI?
    Sorry I forgot to acknowledge you both in my original post!
    Last edited by lydia09; 12-23-2009 at 12:17 PM. Reason: forgot to acknowledge someone

  6. #6
    misson is offline Community Advocate misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,391

    Re: htaccess question

    Quote Originally Posted by descalzo View Post
    Doesn't the Redirect directive give you a loop?
    Yes it will.

    Lydia, you'll need another rewrite condition, something like:
    Code:
    RewriteCond %{REQUEST_URI} !^/index\.html$
    ...
    I say "something like" because the exact pattern you use depends on the top-level URL path and how you want to handle URLs for pages in sub-folders.

    Quote Originally Posted by lydia09 View Post
    if I was just doing a temporary redirect for a folder and its contents (if the page I wanted to redirect to was in that folder), without worrying about a subdomain, [...]
    Basically correct; if you don't care about the server name used in the request, remove that test. You'll also need to adjust the patterns as the request URL will vary, depending on the server name used (e.g. subdomain.maindomain.x10hosting.com/foo/bar vs. maindomain.x10hosting.com/subdomain/foo/bar).
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  7. #7
    peppino87 is offline x10Hosting Member peppino87 is an unknown quantity at this point
    Join Date
    Dec 2009
    Posts
    11

    Re: htaccess question

    Thanks for this good tip.

+ Reply to Thread

Similar Threads

  1. Is Rand Paul a Freemason?
    By allofus in forum Crossfire
    Replies: 6
    Last Post: 10-02-2009, 05:52 AM
  2. Replies: 8
    Last Post: 01-29-2009, 04:01 PM
  3. HTACCESS Help
    By takuhii in forum Free Hosting
    Replies: 2
    Last Post: 09-30-2008, 04:35 PM
  4. Lottery Website (kind of)
    By admintwo in forum Earning Money
    Replies: 4
    Last Post: 12-29-2007, 06:07 PM
  5. Odd question but will I be banned for this?
    By sielk in forum Free Hosting
    Replies: 3
    Last Post: 09-28-2007, 12:29 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