Domanda

I've read some stuff on this but cannot get it clear (or to work):

I have a domain (call it domain1.co.uk) registered with namesco, but pointing to web hosting elsewhere - the name servers are set to those of the hosting company.

With the hosting company, I have a number of different websites in folders under public_html.

I have another domain (call it domain2.co.uk) also registered by namesco, that redirects to one of the websites mentioned above (ie www.domain2.co.uk forwards to www.domain1.co.uk/thisparticularwebsite/home.php).

What I want to do is get a subdomain on domain2 (sub.domain2.co.uk) to reference a specific php script in thisparticularwebsite (ie www.domain1.co.uk/thisparticularwebsite/sub.php).

namesco tell me I can do this by creating an A record or a CNAME record, but it can only reference the top level domain (public_html at domain1), not a sub-directory or script.

What I think need to do therefore is use .htaccess as follows in the root directory of domain1.co.uk

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.domain2\.co\.uk [NC]
RewriteRule ^.*$ http://www.domain1.co.uk/thisparticularwebsite/sub.php [R-301]

or possibly

....
RewriteRule ^.*$ /thisparticularwebsite/sub.php [R-301]

and then create a CNAME record on domain2 for sub (ie sub >> domain1.co.uk).

Is that right?(it doesn't seem to work, though it is unclear what is going on as DNS updates may not have propagated fully yet).

One thing I am not sure if is what should actually turn up in HTTP_HOST - is it the string as typed in by the originating client, or does it get modified along the way by the CNAME records?

È stato utile?

Soluzione

.htaccess code should be

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.domain2\.co\.uk$ [NC]
RewriteRule ^.*$ http://www.domain1.co.uk/thisparticularwebsite/sub.php [L,R=301]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top