开发者

Subdomain URL Rewriting and Web Apps

So a lot of web apps have the customer choose their own subdomain, ie mycompany.webapp.com

Presumably, every subdomain works off the same set of files and the unique subdomain is perhaps stored as a session object. So how does the URL rew开发者_运维技巧riting work?

If someone goes to mycompany.webapp.com, you have to rewrite their unique address to a dynamic page to set the session variable, ie webapp.com/mypage.php?cusomer=mycompany

But then when you redirected, you'd be at webapp.com/theappdirectory/ and not mycompany.webapp.com/

So how do they do it?

PS running IIS but the method should be the same for any server. The big thing for us is we cant do webapp.com/theappdirectory/mycompany/somefile.html, ie all the files reside in one directory and we'll have to set a session variable somehow whilst keeping the subdomain masked.


The redirect can just happen internally:

RewriteCond %{HTTP_HOST} ^([^./]+)\.example\.com$
RewriteCond %1 !=www
RewriteRule ^ mypage.php?customer=%1

To have this work your server/virtual host needs to be configured to accept all sub domains (see for example Name-based Virtual Host Support).


Any web address (inclusive of subdomains) map to an ip address using DNS.

  1. Now these addresses can map to separate web servers where you have documentroot set to whatever you want.

  2. But your question is makes sense when multiple domains/sub-domains are hosted on same physical machine. If you are using apache there is this virtual host setting that can be used that logically divides different domain hosted on same server. It basically maps the Host-Address (like x.example.com, y.example.com) or IP address to a virtual host which sets the initial parameters such as DocumentRoot, PHPAdmin values ..

Check out http://httpd.apache.org/docs/2.0/vhosts/examples.html and http://httpd.apache.org/docs/1.3/vhosts/ for more info

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜