Question

Is it possible to point a subdirectory to another domain?

Posted April 25, 2021 117 views
DNSUbuntu 20.04

I may be asking a stupid question here.
But please bear with me.

I have 165.xxx.xx.xxx and DNS A Record value of mydomain.com is set to this IP address.

I have a subfolder /var/www/html/mysub-folder and wondering if it is possible to set a DNS A Record value of this subfolder to another domain name, anotherdomain.com.

Or do I have to use another droplet?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hello, @okadashinichi2819

You can host multiple websites on your droplet. You can point another domain’s A record to your droplet and then create the virtual host for the domain name and point it to the subdirectory as per your wish.

If you’re using Apache the following article will help you to create another virtual host:

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04

A similar article for Nginx (the version is for Ubuntu 16.04, but the process is relatively the same):

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Regards,
Alex

by Justin Ellingwood
When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu...
  • Thanks for your reply.

    I was reading the article mentioned.
    My 000-default.conf has the following:

    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
    
            <Directory /var/www/html/>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
            </Directory>
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
            <IfModule mod_dir.c>
                DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
            </IfModule>
    
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =mydomain.net
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>
    

    In the article, there is nothing about:

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =mydomain.net
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    

    What do I need to do with these three lines in new files? Or do I need to replace mydomain.net with another domain name?

    by Lisa Tagliaferri
    This tutorial will guide you through setting up multiple domains and websites using Apache virtual hosts on an Ubuntu 18.04 server. During this process, you’ll learn how to serve different content to different visitors depending on which domains they are requesting.