子域 URL 重写和 Web 应用程序
因此,许多 Web 应用程序让客户选择自己的子域,即 mycompany.webapp.com
大概,每个子域都使用同一组文件,并且唯一的子域可能存储为会话对象。那么URL重写是如何工作的呢?
如果有人访问 mycompany.webapp.com,您必须将他们的唯一地址重写为动态页面来设置会话变量,即 webapp.com/mypage.php?cusomer=mycompany
但是当您重定向时,您将位于webapp.com/theappdirectory/ 而不是 mycompany.webapp.com/
那么他们是如何做到的呢?
PS 运行 IIS,但该方法对于任何服务器都应该相同。对我们来说最重要的是我们不能做 webapp.com/theappdirectory/mycompany/somefile.html,即所有文件都驻留在一个目录中,我们必须以某种方式设置一个会话变量,同时保持子域屏蔽。
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 rewriting 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重定向可以在内部发生:
要完成此工作,您的服务器/虚拟主机需要配置为接受所有子域(例如,请参见 基于名称的虚拟主机支持)。
The redirect can just happen internally:
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).
任何网址(包括子域)都使用 DNS 映射到 IP 地址。
现在,这些地址可以映射到单独的 Web 服务器,您可以在其中将 documentroot 设置为您想要的任何内容。
但是当多个域/子域托管在同一台物理计算机上时,您的问题是有意义的。如果您使用 apache,则可以使用此虚拟主机设置来逻辑划分同一服务器上托管的不同域。它基本上将主机地址(如 x.example.com、y.example.com)或 IP 地址映射到虚拟主机,该虚拟主机设置初始参数,如 DocumentRoot、PHPAdmin 值..
查看 http://httpd.apache.org/docs/2.0/vhosts/examples.html 和 < a href="http://httpd.apache.org/docs/1.3/vhosts/" rel="nofollow noreferrer">http://httpd.apache.org/docs/1.3/vhosts/ 了解更多信息
Any web address (inclusive of subdomains) map to an ip address using DNS.
Now these addresses can map to separate web servers where you have documentroot set to whatever you want.
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