1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

htaccess question

Discussion in 'General Scripting Chat' started by dragosdydy, May 20, 2013.

  1. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    Hi guys. I have www.domain.com. On the same host i have www.mom.com and www.dad.com.
    My main domain is www.domain.com and the folder is /public_html and the others are /mom and /dad inside /public_html.

    The /mom and /dad folder are accessible from www.domain.com/mom and www.domain.com/dad .

    How can i block the user or search engines to access www.domain.com/mom and www.domain.com/dad and only let the directories to be accessed from www.mom.com and www.dad.com .

    Until now i used the following htaccess code that redirected the user to the domain in both mom and dad folders:

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.mom.com$
    RewriteRule ^(.*)$ http://www.mom.com/$1 [R=301]

    But i want some code to block the access and not be redirect, just an error page or a not found page. Thanks.
     
  2. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,062
    Likes Received:
    2,872
    Gender:
    Male
    Put a robots.txt in the root domain?
     
    • Thanks Thanks x 1
  3. rutix

    rutix Junior Member

    Joined:
    Sep 6, 2012
    Messages:
    102
    Likes Received:
    12
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.mom.com$
    RewriteRule ^(.*)$ http://www.mom.com/$1 [R=404]
     
    • Thanks Thanks x 1
  4. roach

    roach BANNED BANNED

    Joined:
    Sep 8, 2009
    Messages:
    740
    Likes Received:
    395
    I also believe the robots.txt may be your best answer
     
  5. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,287
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    SEs never seem to care about robots.txt.. best would be to block it in htaccess

    OPs case is one of the best examples why i always put seperate sites in separate directories outside public_html directory..
     
    • Thanks Thanks x 1
  6. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    Thanks but i doesn't work. Still when entering www.domain.com/mom it redirects me to www.mom.com. Only if i write mom.com without www i'm getting the error.

    Anyone with another solution? Thanks!
    I mention that on /mom and /dad i have wordpress installed.
    I'm looking for a .htaccess code that can be applied in the /public_html folder.
     
    Last edited: May 20, 2013
  7. kharm

    kharm Power Member

    Joined:
    Feb 9, 2009
    Messages:
    525
    Likes Received:
    97
    Occupation:
    Entrepreneurship
    You don't need HTACCESS for this. If you're using shared hosting simply use the subfolder for your addon domain.

    If users can still access your directories via public_html (www.domain.com) - that you may need to use HTACCESS to disallow access to subfolders.
     
  8. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    I'm working for someone now, and i have only ftp access. I have 3 domains on the same host.

    www.domain.com = public_html
    www.mom.com = public_html/mom
    www.dad.com = public_html/dad

    I just want to make www.domain.com/mom and www.domain.com/dad unreachable.
     
  9. Iapetos

    Iapetos Newbie

    Joined:
    Aug 3, 2012
    Messages:
    20
    Likes Received:
    9
    Had to send you a method to try as a PM since the system think's I'm posting a URL
     
  10. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    Thank you all for your replies. I don't think i'll ever find a solution. I think it's the hosting problem that automatically redirect the www.domain.com/mom to www.mom.com even i'm telling in the .htaccess not to do so. I tried all the solutions found on google and recommended by you and still no result. Thanks a lot.
     
  11. Iapetos

    Iapetos Newbie

    Joined:
    Aug 3, 2012
    Messages:
    20
    Likes Received:
    9
    Is mom and dad setup as subdomains of your domain I.e. through your control panel? If so, that would mean they never see your domains htaccess
     
  12. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    I don't really know. I only have ftp access :(
     
  13. bigkapp

    bigkapp Regular Member

    Joined:
    Dec 8, 2010
    Messages:
    461
    Likes Received:
    369
    I'm not to good at writing code to the .htaccess file but it sounds like you need to 301 redirect www.domain. com/mom and www.domain. com/dad to www.mom. com and www.dad. com
     
    • Thanks Thanks x 1
  14. -Jericho-

    -Jericho- Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jan 10, 2010
    Messages:
    2,849
    Likes Received:
    1,704
    Location:
    Stalking My Ex-Wife
    You could try this. Create an htaccess file and place it in those directories with this code:

    Code:
    
    # Block External Access
    deny from all
    
    Or just 301 redirect it like mentioned above. Or something like this for those directories:

    Code:
    
    [COLOR=#ffffe0]RewriteEngine on
    RewriteBase /
    RewriteRule ^mom/(.*)$ http:[I]//www.domain.com/ [R=301,L][/I][/COLOR]
     
    • Thanks Thanks x 1
    Last edited: May 21, 2013
  15. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,062
    Likes Received:
    2,872
    Gender:
    Male
    MMM if that is the case, then htaccess can be used easily :)