Page 1 of 1

Redirect Subdomain Without Changing URL

Posted: Fri Apr 03, 2020 8:42 am
by vebinua
Hey Guys,

I hope this finds you all well. I have a primary domain domain.com created and I wanted a subdirectory sub.domain.com created too. As suggested, I simply need to treat it as another web domain so I created one for sub.domain.com.

I, however, wanted sub.domain.com to point to a directory/folder on my primary domain domain.com like the following:
sub.domain.com ---> domain.com/sub

where sub is simply a folder/directory, and that the URL stays the same sub.domain.com (not changing to domain.com/sub)

Is this possible via .htaccess? how do I go about this?

My machine runs on Centos 7 (with apache2 + Nginx). Thank you!

Re: Redirect Subdomain Without Changing URL

Posted: Thu Apr 09, 2020 1:21 am
by plutocrat
I'm supposing you have your reasons for doing this, rather than just moving the files into the subdomain public_html directory ...

Two ways of doing it that I can think of.

a) Remove subdomain public_html directory, and symlink it to the other place. eg.
ls ~/web/
domain.com
sub.domain.com
cd sub.domain.com
mv public_html public_old # might need sudo?
ln -s /home/admin/web/domain.com/public_html/directory/ ./public_html/

b) Create a new template for your subdomain site based on one of the vesta default templates. Edit the path within that to point to the correct directory. Save the template with a different name (mysubdomain.tpl / stpl). Select that template for your sub.domain.com from the vestacp interface. I can't be more specific with this one as I don't know what your set up is. Search the forum for guides.