Pointing subdomain to magento installed on main domain -Multi domain Magento

I have installed magento in
.htaccess in this folder is:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule .* /pub/$0 [L]
DirectoryIndex index.php

I have added a subdomain (or if i added a completely different domain) and it has its own directory:

what should the .htaccess file in this folder look like to direct it to the magento installation in the domain.com/public_html folder?

I tried doing custom document root: set to the domain.com/public_html directory, but this would only redirect my sub.domain.com to the domain.com

I have magento set to receive both domains.
Hopefully someone has done this before and can give me some advice. Much appreciated…

I would suggest to add sub.domain.tld as alias to domain.tld, you can do this while editing the web sertings of domain.tld.

thanks for the reply ScIT, but my intention is to eventually have a different domain in the same magento install (multiple domain). So I’m trying to see how this can be accomplished before moving over existing domain.

it looks like i have to add a nginx.hsts.conf file in my home/magento/conf/domain.com directory.

i tried creating this file:

map $http_host $MAGE_RUN_CODE {
default ‘’;
domain.com domainwebsite;
sub.domain.com subdomainwebsite;

server {
listen 80;
server_name domain.com sub.domain.com;
set $MAGE_ROOT /home/magento/web/domain.com/public_html;
set $MAGE_MODE developer;
set $MAGE_RUN_TYPE website;
include /home/magento/conf/web/domain.com/nginx.conf.sample;

but i got error on: $ nginx -t
“map directive not allowed in …”

Very little info on this and most information out there is not similar to Hestiacp type set up.

the nginx.conf files seem to have the instructions to look for a nginx.hsts.conf* file if it exists:
" include /home/magento/conf/web/domain.com/nginx.hsts.conf*; "

Anyone running similar scenario?

Once again, if you add the subdomain as alias, you should be able to use the multiple shop/domain scenario. As far as i know, you just need to set the store code over htaccess - google should lead you to the right way.

Or are you talking about a test domain? To verify if the shop works properly?

1 Like

regardless if it’s a test domain or not, I agree a simple alias is the way to go.
with that the sub-domain points directly to the magento docroot and magento itself can take care of the rest. no further rewrite/redirect needed.

theoretically you could also just symlink folders on the filesystem layer though…

Thanks for the feedback,

My intention is to have domain1.com and domain2.com in the same magento. Therefore i don’t think i can use the alias (subdomain) type set up.
To test the configuration, before moving my active domain to this VPS, i thought i would try it using a subdomain as if it was a unique domain.
I would point the root directory of domain2.com as same root as domain1.com where magento is installed.

I have configuration set up to receive the the 2 distinct domains in magento based on different website codes.

however both domains are just ending up in the same place, domain1.com (as if domain2.com is just redirected to domain1.com)

Is there no editing of code required in either nginx.conf.sample or in a new nginx.hsts.sample files? tutorials online all mention editing these files. I’m just confused because there are nginx.conf.sample files in multiple places, some needing root server access (which i have if necessary) but also in the public_html folder

btw i do not have apache installed. only nginx, so i assume i do not need to change .htaccess file.

this is what the ALIAS functionality is for. just put it in there and you’ll see.

PS: it still might require you to have different nginx config if you cannot have a .htaccess taking care of the rewrites. still handling this as two seperate web-domains in the panel defeats the purpose and makes thing more complex

Perhaps it might be simpler to have 2 separate magento installations after all. one for each domain.
I cant seem to get it working the way i was hoping.
I hear what you mean about the Alias/subdomain set up. But I’m looking to do this with 2 completely unique domains with there own SSL’s and mail servers. So i think the proper way to do it must be 2 separate domains in the panel.
I’m using nginx server only.
I appreciate the help, falzo and ScIT. It’s probably my lack of skill in this field that is making this difficult for me. :frowning:

The point is not to save time installing Magento but the time you save managing only one Magento over time.

no, the proper way is to make them aliases in the web-doman. that’s the beauty of lets encrypt - it is possible to get a multi-domain cert including totally different domain names.
as said you most likely need to customize the nginx-config still, but that is just because you don’t have an .htacces which magento could handle itself.

but hey, your choice… we can’t do more than recommend how to do it.

and btw: mail is it’s own battlefield and you can still easily seperate the domains on that level, while they are aliases on the webpage level. you even need to add the alias domain extra in the mail section.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.