如何将 URL 重定向到主机文件中的另一个 URL,而不是将 IP 重定向到 URL?

发布于 2024-09-10 16:20:57 字数 50 浏览 6 评论 0原文

如何将 URL 重定向到主机文件中的另一个 URL,而不是将 IP 重定向到 URL?

How do I redirect a URL to another URL in the hosts file, rather than redirecting an IP to a URL?

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

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

发布评论

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

评论(2

生生不灭 2024-09-17 16:20:57

你不能。 DNS(或主机文件)可让您查找给定的 IP 地址
主机名。在这个网络级别上不存在重新映射 URL 的概念。
这需要在您的 Web 服务器配置中完成。

You can't. DNS (or the host files) lets you look up IP addresses for a given
host name. There is no concept of remapping URLs at this level of networking.
This needs to be done in your web server configuration.

忆离笙 2024-09-17 16:20:57

您可以安装localhost(MAMP,LAMP ..等),并将所有链接重定向到127.0.0.1,然后创建脚本以重定向到任何网站。

这是 PHP 示例

<?php
function curPageURL() {
    $pageURL = "http://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $pageURL;
}
// if pageURL is facebook , redirect to medium.com
if(curPageURL() == "http://www.facebook.com/")
    header('Location: http://www.medium.com');
?>

you can install localhost (MAMP ,LAMP ..etc) , and redirect all links to 127.0.0.1 , then create script to redirect to any website .

here's PHP example

<?php
function curPageURL() {
    $pageURL = "http://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $pageURL;
}
// if pageURL is facebook , redirect to medium.com
if(curPageURL() == "http://www.facebook.com/")
    header('Location: http://www.medium.com');
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文