子域 URL 重写和 Web 应用程序

发布于 2024-09-01 09:11:46 字数 457 浏览 6 评论 0原文

因此,许多 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吝吻 2024-09-08 09:11:46

重定向可以在内部发生:

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

要完成此工作,您的服务器/虚拟主机需要配置为接受所有子域(例如,请参见 基于名称的虚拟主机支持)。

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).

佞臣 2024-09-08 09:11:46

任何网址(包括子域)都使用 DNS 映射到 IP 地址。

  1. 现在,这些地址可以映射到单独的 Web 服务器,您可以在其中将 documentroot 设置为您想要的任何内容。

  2. 但是当多个域/子域托管在同一台物理计算机上时,您的问题是有意义的。如果您使用 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.

  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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文