3

We are creating a SAAS base application, where every company get its own subdomain. But if the company wants to configure another domain with our application, they can do that.

e.g. I am a company registered with the application www.saas.com, i got the subdomain company.saas.com, now i want to point my company.com domain to the company.saas.com, so how we can achieve this?

i know it can be done using Cname but is there a way to dynamic update Cname?

2 Answers 2

1

This depends entirely on how your application performs the hostname detection. E.g. if it runs on HTTPS, you'll need to add a virtual host on your web server. We could deduce, based on that you currently use subdomain.saas.example.com and the software is able to detect that, that this should be possible. You'll just use the same method for hostname identification than with the current solution.

On DNS level you should use an A record pointing to the same IP address. That's because using a CNAME record only causes another DNS lookup for the company.saas.example.com IN A record and it doesn't cause any change in the hostname detected, so you wouldn't get any benefit from using it; i.e. it's not a shortcut for preventing configuration of this hostname detection method.

If you wish to use CNAME (for example if the IP address for *.saas.example.com may change without acknowledging the customer), you should advice using a subdomain, e.g. saas.example.net instead of example.net. This is because when using a CNAME record you are not able to use any other records on the same hostname. With the domain name itself this means you lose the ability to add MX, TXT, NS etc. records. That would prevent using the same domain for email etc.

11
  • What kind of server configuration i need? Do i need dedicated server or it can work on shared hosting as well? I am using apache and codeigniter/php.
    – Naveen
    Jun 20, 2017 at 12:26
  • Share your Apache configuration for *.saas.example.com by adding it to your question. Then, I may help you to add an example virtual host for a custom domain. If the domain isn't always a direct match against the subdomain, you'll need to add one new virtual host for every single domain. But if you can sell a SaaS solution to a company, the effort:benefit rate in that would still be excellent. Jun 20, 2017 at 12:32
  • I am not sure how i can check Apache configuration. I am on shared hosting. Do you think we need dedicated server ?
    – Naveen
    Jun 20, 2017 at 13:37
  • If you can't access Apache configuration, you'll need to ask for an addition every time a new domain appears. (Possibly you can do this via some web control panel, but they are off-topic here.) Therefore, a dedicated server (or VPS) would be ideal for this. Jun 20, 2017 at 13:47
  • So if i have dedicated server, how should i create virtual host?
    – Naveen
    Jun 22, 2017 at 8:01
0

You can use RewriteRule's to redirect requests to a specific DocumentRoot and you can add the rule's dynamic to a .htaccess file.

It would be better to add virtualhosts to Apache's config files but then you have to restart Apache after every change.

.htaccess:

RewriteEngine On

RewriteCond %{HTTP_HOST} (clientone.saas.example.com)
RewriteRule ^(.*)$ /clientonefolder/$1 [R=301,L]

RewriteCond %{HTTP_HOST} (clienttwo.saas.example.com)
RewriteRule ^(.*)$ /clienttwofolder/$1 [R=301,L]
1
  • What would add the new domain into ServerAlias, if the site isn't the default virtual host? Restarting Apache isn't necessary either; you can restart gracefully or reload. Jun 20, 2017 at 13:50

Not the answer you're looking for? Browse other questions tagged .