Php – Run single php code using multiple domains

domainPHPweb-hosting

I have a php code/site at xyz.com. Now I want to run the same site using multiple domains means when somebody open domain1.com, domain2.com ,domain4.com, so on urls, it should run the code/side that is at xyz.com

I know one way to do this. I can host all these domains to the server where xyz.com is hosted so all domains will point to same peace of code/site.

n above solution i need to hosted the domains manually. Is there any other way to do this as I want to add domains dynamically?

Thanks in advance!

Best Answer

If you have control over your Apache configs on your server, just change the default virtual host's DocumentRoot to /your/site/root. As long as your domains' A records (or you can use CNAMEs) all resolve to your Web server's IP address, Apache will dish up the default website if there's no match for another virtual host.

This is a very common method of doing it, so unless you need to have separate Web servers for each domain, there's nothing more manual with this method than any other method (like using rsync to copy your PHP files to another server); DNS needs to be setup regardless.

You can setup wildcard DNS for sub-domains you control so that *.yourdomain.com (foo.yourdomain.com, bar.yourdomain.com, etc.) all resolve to the same A record, but not with TLDs (unless you happen to own the .com TLD).

Related Topic