Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a site installed at, for argument's sake, /var/www/site, and have a subdomain set up so that it can be accessed via subdomain.domain.com.

How do I stop it also being accessed via domain.com/site? This obviously works as it is a subdirectory in the root htmldir of /var/www.

Will Google currently see this as two different sites, too?

Thanks.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You could use a rewrite rule to make sure the content is only accessed through the subdomain. Create a .htaccess file in the site directory that you want to work only through it's subdomain:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
RewriteRule ^/(.*)$ http://subdomain.domain.com/$1 [L,R=301]

As for the Google question, Google generally sees subdomains as separate sites as far as I know.

share|improve this answer
    
Thanks, I'll do that. What I meant about the Google thing was, will it see subdomain.domain.com and domain.com/site as two entities? –  Oliver Haslam Dec 30 '12 at 1:14
    
For some reason, doing this stops me from accessing it at all. I obviously changed the url to reflect mine, but I get permission denied. –  Oliver Haslam Dec 30 '12 at 19:05

Regarding the google thing, your site will be penalized for SEO ranking as google will see it as two different entity and will negative rank your site.

Also, I am not even sure why you are running the other domain from the same document root. The best solution what I will say is to move it out of main site's document root and create a new document root somewhere else, and update your virtual host settings. I don't see a good reason here to even mess with the rewrite rule, when you don't need it at all (Unless there is some specific reason why you did it which I am missing and would like to understand).

share|improve this answer
    
So, the best bet is to create a new dir called 'sites' for example, and keep everything in its own dir in there? That would obviously keep everything separate. –  Oliver Haslam Jan 1 '13 at 18:34
    
Yes, that's the best practice, I will say. –  GeekRide Jan 2 '13 at 6:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.