Mod Rewrite - How To 404 an entire subdomain?

magicink

New member
Feb 5, 2011
160
2
0
So I'm transferring a sold site to a client's host. Apparently on bluehost, creating an add on domain also creates a subdomain on your primary domain with a duplicate version of your entire site. I believe its a cpanel issue not a host specific thing, but all the hosting providers I've used in the past had things setup to avoid this SEO nightmare.

I used a 301 redirect so that addondomain.primarydomain.com goes to addondomain.com, but I'm not really sure how to make it so that addondomain.primarydomain.com/page1.php goes to addondomain.com/page1.php. I've tried, but my mod rewrite knowledge is pretty limited.

It seems like the simple solution would be to just 404 the whole subdomain, since I don't really care if it redirects. I tried numerous variations of the following code, but none of it seems to work.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^addondomain.primarydomain.com(.*)$ [NC]
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^(.*)$ - [L,R=404]

I'm not really sure why this doesn't work. Possibly because I'm retarded, but I did get the following to work to 404 the contents of primarydomain.com/addondomain.com/

RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addondomain.com/(.*)$
RewriteRule ^(.*)$ - [L,R=404]

I would really appreciate it if someone could point me in the right direction. Why does the latter work when the former doesn't? Also, flaming is more than welcome, especially if it comes with a solution. Thanks.
 


It might be easier to put a .htaccess in primarydomain.com/addondomain.com/

that just redirects 'everything'.
 
It might be easier to put a .htaccess in primarydomain.com/addondomain.com/

that just redirects 'everything'.

Thanks for the reply.

The .htaccess file is already in primarydomain.com/addondomain.com/. primarydomain.com/addondomain.com/ can be accessed by visiting addondomain.com or, addondomain.primarydomain.com.

I want to 404 everything accessed in the latter without affecting the former. If I just 404'd everything in primarydomain.com/addondomain.com, then addondomain.com would be affected as well.