Redirecting subdomain of add-on domain on hostmonster.com

654 Views Asked by At

I am having issues with restricting access to only the add-on domain. I do not wish to be able to access the files through the primary domain.

I have my primary domain hosted with hostmonster.com which is mydomain.co.uk. I have three 'addon' domains:

addondomain1.com

addondomain2.com

addondomain3.com

They could be accessed by visiting

addondomain1.mydomain.co.uk OR mydomain.co.uk/domains/addondomain1

addondomain2.mydomain.co.uk OR mydomain.co.uk/domains/addondomain2

addondomain3.mydomain.co.uk OR mydomain.co.uk/domains/addondomain3

I have added a subdomain 'dev' for addondomain1 which can be accessed by visiting

mydomain.co.uk/domains/addondomain1/dev OR dev.addondomain1.mydomain.co.uk

If anyone can give me some pointers as to what my .htaccess should look like that would be great. I assume I may have to have two .htaccess files. One in the 'addondomain1' directory and one in the 'dev' directory within that.

What I have so far: .htaccess

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^(www\.)?addondomain1.$ [OR]
    RewriteCond %{HTTP_HOST} ^dev.addondomain1.mydomain.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.dev.addondomain1.com$
    RewriteRule ^/?dev/(.*)$ http://dev.addondomain1.com/$1 [L,R=301]

    RewriteCond %{HTTP_HOST} ^addondomain1.mydomain.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.addondomain1.mydomain.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.addondomain1.com$
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^(.*)$ http://addondomain1.com/ [R=301,L]

    Redirect 301 /domains/addondomain1 http://addondomain1.com

I currently get an error in the browser stating that it cannot load the page because too many redirects are occurring. It appears to be stuck in a loop.

The result that I would like is to be able to access the files solely through:

dev.addondomain1.com

1

There are 1 best solutions below

0
anubhava On

On inside mydomain.co.uk/domains/addondomain1/dev/.htaccess insert this rule as your first rule:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^dev\.addondomain1\.com$
RewriteRule ^ - [F]