【问题标题】:How do I use URL forwarding to a specific webpage on the target domain?如何使用 URL 转发到目标域上的特定网页?
【发布时间】:2015-01-04 09:43:19
【问题描述】:

我正在学习转发 URL,但不确定我是否使用了正确的术语。这是我到目前为止所做的以及我正在努力完成的事情。我创建了一个网站“ABC.com”。我从 freenom.com 获得了一个名为“XYZ.cf”的免费域。 Freenom 让我将任何访问 XYZ.cf 的人“转发”到我的网站 ABC.com。

默认情况下,任何输入 XYZ.cf 的人都会被转发到我的 ABC.com 网站的 index.htm 文件。我希望能够给人们这个 URL:“XYZ.cf/special1.htm”,他们将能够访问我的 ABC.com 网站上的 special1.htm。它不仅仅是 special1.htm,任何看起来像“XYZ.cf/variable.htm”的文件都将被重定向到我的 ABC.com/variable.htm,其中变量将是任何文件名。

例如:

If I give people the url XYZ.cf/1.htm, they should end up at ABC.com/1.htm.
If I give people the url XYZ.cf/2.htm, they should end up at ABC.com/2.htm.
If I give people the url XYZ.cf/3.htm, they should end up at ABC.com/3.htm.
If I give people the url XYZ.cf/4.htm, they should end up at ABC.com/4.htm.
If I give people the url XYZ.cf/5.htm, they should end up at ABC.com/5.htm.
If I give people the url XYZ.cf/6.htm, they should end up at ABC.com/6.htm.
If I give people the url XYZ.cf/7.htm, they should end up at ABC.com/7.htm.

我只有 7 个这样的文件。而已。我需要做什么?

【问题讨论】:

  • 如果您对多个 URL 执行此操作,您应该为此查看服务器端 URL 别名技术。随着网站的发展,在文件中执行此操作将需要大量工作。
  • 我想我想为大约 7 个 URL 执行此操作。也就是说,XYZ.cf/1.htm 到 XYZ.cf/7.htm 应该转发/重定向到 ABC.com/1.htm 到 ABC.com/7.htm。最简单的实现方法是什么?

标签: html .htaccess


【解决方案1】:

也许你应该看看mod_rewrite 并在你的.htaccess 文件中声明一个重写规则。

更多信息:http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

【讨论】:

    【解决方案2】:

    将此代码添加到您要重定向的页面的头部。

    <meta http-equiv="refresh" content="0; url=INSERT URL YOU WANT TO REDIRECT TO HERE/" />
    

    【讨论】:

    • 谢谢,我改写了我的问题以更准确。我不想重定向到一个网页。我希望能够重定向到用户键入的任何网页。例如,如果用户输入了 XYZ.cf/Tom.htm,它应该真正转到 ABC.com/Tom.htm。如果用户键入 XYZ.cf/Bob.htm,它应该转到 ABC.com/Bob.htm。让我们假设 Tom.htm 和 Bob.htm 都已经存在于 ABC.com 域中
    【解决方案3】:

    在.htaccess文件中,添加:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !ABC.com$ [NC]
    RewriteRule ^(.*)$ http://ABC. com/$1 [L,R=301]
    

    【讨论】:

    • 谢谢,我改写了我的问题以更准确。我希望能够分发任何 variable.htm 文件名,并让用户在 ABC.com/variable.htm 上定向到它。所以,我不想只重定向到 special.htm。
    • 那么你在哪里定义变量。
    • 我不明白你的问题。也许这个例子可能有助于阐明我正在尝试做的事情。 XYZ.cf/1.htm 到 XYZ.cf/7.htm 应该转发/重定向到 ABC.com/1.htm 到 ABC.com/7.htm。最简单的实现方法是什么?
    • 你有规定吗?哪个页面会被重定向到哪个页面?
    • 如果用户输入 XYZ.cf/foobar.htm,它将转到 ABC.com/foobar.htm。如果用户输入 XYZ.cf/jewel.htm,它将转到 ABC.com/jewel.htm。如果用户键入 XYZ.cf/nguyen.htm,它将转到 ABC.com/nguyen.htm。我有大约 7 个我想做的文件。而且我不知道该怎么做。
    猜你喜欢
    • 1970-01-01
    • 2017-12-12
    • 1970-01-01
    • 2017-03-26
    • 2015-05-14
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多