htaccess question

dragosdydy

Junior Member
Joined
Jan 23, 2012
Messages
116
Reaction score
50
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.
 
Put a robots.txt in the root domain?
 
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mom.com$
RewriteRule ^(.*)$ http://www.mom.com/$1 [R=404]
 
I also believe the robots.txt may be your best answer
 
Put a robots.txt in the root domain?

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..
 
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mom.com$
RewriteRule ^(.*)$ http://www.mom.com/$1 [R=404]

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:
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.
 
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.

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.
 
Had to send you a method to try as a PM since the system think's I'm posting a URL
 
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.
 
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
 
I don't really know. I only have ftp access :(
 
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]
 
Last edited:
MMM if that is the case, then htaccess can be used easily :)
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..
 
Back
Top