How do i offer Basecamp/SAAS App like sub domains to clients?
For example, my website URL is http://www.example.com whenever the user signup i want to offer them url like http://company.example.com which should load files/contents from /app directory of the website.
And later i want them to choose their own domain/sub-domain via CNAME, so that they can have URL like http://clients.mywebsite.com
I want to do this in Pure PHP and .HTACCESS and offcourse everything happens automatically.
And i want to keep URL structure same.., that is http://company.example.com/login, http://company.example.com/accounts, http://company.example.com/files/style.css though these files are located inside /app directory i want them to be accessed like this.
I can handle all PHP functions, i need help with .htaccess codes and how to go about CNAME.
Make sure DNS resolves all subdomains by including following in domain’s zone:
Next, configure web server to recognize all incoming requests, for Apache, you need to add following to VirtualHost:
That’s it. The only thing remaining is the logic in the code, you need to check host name to see whether a request was done to example.com or foo.example.com.
Updated with more details.
So, assuming your files are in
/path/to/files/app, you need to configure virtual host like this:This way all requests will resolve to
/appdirectory. To test it, apply above DNS configuration or simply add the domains you want tested into yourhostsfile,/etc/hostson Linux orc:\Windows\System32\drivers\etc\hostson Windows.