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.

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

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏