域名屏蔽/指向 Web 应用程序的目录?

发布于 2024-07-30 20:07:29 字数 1269 浏览 4 评论 0原文

我构建了一个 LAMP Web 应用程序,让用户创建自己的个人资料页面,他们可以在其中上传简历和作品集。 个人资料的 URL 类似于

http://jobbank.com/user/johndoe

John Doe 注册了域名 http://johndoefreelancer.com 并且他希望它指向 http://jobbank.com/user/johndoe。 任何访问 johndoefreelancer.com 的人都不应该知道它是由 http://jobbank.com/user/johndoe< 驱动的/a>. 这意味着浏览器 URL 应持续显示如下地址:

http://johndoefreelancer.com/aboutme (实际上指向 jobbank.com/user/johndoe/aboutme) 指向 jobbank.com/user/johndoe/portfolio)

http://johndoefreelancer.com/portfolio(实际上 ,单击任何链接 [a href=""] 将使您继续访问 johndoefreelancer.com,而不是将您转到 jobbank.com。

我的问题是,实现这一目标的最佳方法是什么?

我正在考虑: 1) 指导用户如何通过屏蔽进行域名转发

2) 指导用户填写用户配置信息中的 $homeUrl 字段,该字段将保存到数据库中

3) 在我的 PHP 代码中,如果 $homeUrl 存在,则替换所有 [ a href="$_SERVER['HTTP_HOST']"] 和 [a href="$homeUrl"]

这是正确的方法吗? 有没有更好的办法?

I built a LAMP web application that let's users create their own profile page where they can upload their resume and portfolio. The url for a person's profile will be something like

http://jobbank.com/user/johndoe

John Doe registers the domain name http://johndoefreelancer.com and he wants it to point to http://jobbank.com/user/johndoe. Anyone who visits johndoefreelancer.com should not be aware that it's driven by http://jobbank.com/user/johndoe. This means that the browser url should persistently show addresses such as:

http://johndoefreelancer.com/aboutme (really points to jobbank.com/user/johndoe/aboutme)
http://johndoefreelancer.com/portfolio (really points to jobbank.com/user/johndoe/portfolio)

Additionally, clicking on any links [a href=""] should keep you at johndoefreelancer.com instead of sending you to jobbank.com.

My question is, what is the best way to achieve this?

I'm considering:
1) Give instructions to users on how to domain forward with masking

2) Instruct users to fillout the field $homeUrl in their User Profile information, which is saved to the database

3) In my PHP code, if $homeUrl exists, replace all [a href="$_SERVER['HTTP_HOST']"] with [a href="$homeUrl"]

Is this the right approach? Is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

风筝有风,海豚有海 2024-08-06 20:07:33

我目前能想到的唯一实用方法是:

  1. 在用户个人资料中添加一个字段
    对于域名

  2. 告诉用户让 DNS 主机条目指向您的 IP(或您的主域名)

  3. 创建一个虚拟主机,这是您可能拥有的第一个虚拟主机。 (*)

  4. 在此虚拟主机中创建一个index.php脚本,用于在用户配置文件中查找所请求的域名并显示页面。

您可能需要为页面上打印的 URL 实现开关。 例如。 如果您访问特殊索引页面,请使用 / 作为“base href”,在所有其他情况下 /user/username 是“base href”

*) 如果 apache 收到对其不知道的名称的请求(因为它没有 ServerName|Alias虚拟主机,它使用第一个虚拟主机作为后备。

The only practical way i could think of in the moment is:

  1. add a field in the users Profile
    for a domainname

  2. tell the users to let point the DNS host entry to your IP (or the main domainname of you)

  3. create a virtual host which is the FIRST of alle vhosts you might have. (*)

  4. in this virtual host create an index.php script which looks up the requested domainname in the user profile and display the page.

You might need to implement a switch for the urls you print on the page. eg. if you came over the special index page use / as "base href", in all other cases /user/username is "base href"

*) If apache gets a request for a name it dont know (because its no ServerName|Alias of an vhost, it uses the first Vhost as fallback.

半窗疏影 2024-08-06 20:07:32

另一种方法是告诉您的用户将他们的域指向您的 IP,并将它们设置为基于名称的虚拟主机。 好处是:

  1. 用户可以更轻松地设置然后转发屏蔽(后者甚至可能无法实现,具体取决于注册商)
  2. 您不必在 PHP 代码中处理 URL 重写。

如果您不必为 URL 使用 /user/johndoe 前缀(您实际上并不需要这样做,因为您可以在代码中进行域查找来确定用户),那么设置会更容易id),但也可以使用前缀 - 只是在这种情况下 mod_rewrite 设置必须更多地参与(您需要为每个域执行此操作)。

An alternative approach would be to tell your users to point their domains to your IP and set them up as name-based virtual hosts. The benefits are:

  1. It's much easier for the user to set up then forward with masking (the latter may not even be possible depending on registrar)
  2. You don't have to deal with URL rewriting in your PHP code.

This would be easier to setup if you did not have to use /user/johndoe prefix for your URLs (which you don't really need to because you can do a domain lookup in your code to determine user id), but is possible with the prefix as well - it's just that mod_rewrite setup would have to be more involved in that case (you'll need to do it per domain).

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