I have a website (site1.com) that has another site being built within it (site1.com/newsite).

My client wants to create a new domain name and have it point to the directory that houses the new site.

As a front end dev I am very confused as to how to go about this. Is this something that can be in htaccess? What would I place on the registrars end?

Would anyone know the best way to do this?

2 Answers 2


Let's assume that

  • your client's new domain is client.com

  • your server's ip address (where you have site1.com/newsite) is

  • the path to newsite on your server is /srv/www/newsite

  • your webserver is Apache

First, you need to create a virtual host in Apache, containing at least:

<VirtualHost *:80>
    DocumentRoot /srv/www/newsite
    ServerName www.client.com
    ServerAlias client.com

If you're on Debian based systems, you can just create a new file clientsite.com in /etc/apache/sites-available and put that inside it.

Then run a2ensite client.com and service apache2 reload and you're done.

If you're not on Debian, look on how to add a vhost to your specific distribution apache (CPANEL also has a vhost section for Apache).

Now in your client's registrar, they need to point client.com and www.client.com to your server's ip address

Additional: as mentioned in the previous reply, you should prevent access to the /newsite dir so people can only access it by the client.com address, and not by site1.com/newsite. To do that, in your site1.com vhost, put this

<Directory "/newsite">
  Deny from all

Update the question with more information (include at your OS and webserver and if you have CPANEL or anything similar). The more precise your question is, the more precise the replies you get will be.

  • This does not work. It prevents access to client.com altogether Dec 20, 2021 at 13:41

If you have access to your current hosting setup, you can configure a new virtual host for the domain in your web server.

You would point the root directory of that virtual host to the newsite directory.

Then, you would just enter the IP address of your current web server as the new domain's A records.

You might also want to exclude access to the newsite directory via the old site with .htaccess rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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