doumou8527 2011-01-08 08:13
浏览 55
已采纳

如何为SAAS应用程序提供自定义子域

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.

  • 写回答

1条回答 默认 最新

  • dongqiao9015 2011-01-08 08:37
    关注

    Make sure DNS resolves all subdomains by including following in domain's zone:

    *.example.com. 14400 IN A HereBeIP
    

    Next, configure web server to recognize all incoming requests, for Apache, you need to add following to VirtualHost:

    ServerAlias *.example.com
    

    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:

    <VirtualHost>
        SeverName example.com
        ServerAlias *.example.com
        DocumentRoot /path/to/files/app
        # plus what else is needed
    </VirtualHost>
    

    This way all requests will resolve to /app directory. To test it, apply above DNS configuration or simply add the domains you want tested into your hosts file, /etc/hosts on Linux or c:\Windows\System32\drivers\etc\hosts on Windows.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?