PHP 内联 URL 重定向?

发布于 2024-12-05 18:38:02 字数 1206 浏览 1 评论 0原文

我想知道是否有可能让人们只需输入链接即可:

并在人们访问时让它真正转到真正的链接。

这就是我所拥有的,但我不知道如何实施。

<?php
if( $_GET["k"] == "custom" ) header( "Location: {$_POST["first"]}_{$_POST["last"]}" );

$file = fopen( "link.php", "r" );

$data = fread( $file, filesize( "link.php" ) );


$first = $_GET["n"];
$last = fixN( $last );
$data = str_replace( "first", ucfirst( strtolower( $first ) ), $data );
$data = str_replace( "last", ucfirst( $last ), $data );


print  $data;

}
?>

在页面上;

<BODY onLoad="first">

即使你做了链接,它也不会只抓取最后一部分。这就是我需要它重定向到的地方。


<?php
if (isset($_SERVER['REQUEST_URI'])) AND filter_var(trim($_SERVER['REQUEST_URI']),     FILTER_VALIDATE_URL)) {

    header('Location: ' . $_SERVER['REQUEST_URI']);

}
?>
<html>
<head></head>
<body>
<a href="first">first</a>
</body>
</html>

这是确切的链接 http://LikeTreasure.com/google.com

我不知道出了什么问题与它。

即使您指定文件类型 http://LikeTreasure.com/file.html

它似乎总是发送整个网址。

I was wondering if it was possible to make it where someone could just input the link:

and have it actually go to the real link when people visit.

This is what I have, but I don't know how to implement.

<?php
if( $_GET["k"] == "custom" ) header( "Location: {$_POST["first"]}_{$_POST["last"]}" );

$file = fopen( "link.php", "r" );

$data = fread( $file, filesize( "link.php" ) );


$first = $_GET["n"];
$last = fixN( $last );
$data = str_replace( "first", ucfirst( strtolower( $first ) ), $data );
$data = str_replace( "last", ucfirst( $last ), $data );


print  $data;

}
?>

On the page;

<BODY onLoad="first">

Even if you do the link, it wont only grab the last part. Which is what I need it to redirect to.


<?php
if (isset($_SERVER['REQUEST_URI'])) AND filter_var(trim($_SERVER['REQUEST_URI']),     FILTER_VALIDATE_URL)) {

    header('Location: ' . $_SERVER['REQUEST_URI']);

}
?>
<html>
<head></head>
<body>
<a href="first">first</a>
</body>
</html>

This is the exact link http://LikeTreasure.com/google.com

I don't know what's wrong with it.

even if you specify a file type http://LikeTreasure.com/file.html

It always seems to send the entire url.

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

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

发布评论

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

评论(1

酒解孤独 2024-12-12 18:38:02

只要您将 URL 重写为 PHP 文件...

if (isset($_SERVER['REQUEST_URI'])) AND filter_var(trim($_SERVER['REQUEST_URI']), FILTER_VALIDATE_URL)) {

    header('Location: ' . $_SERVER['REQUEST_URI']);

}

如果设置了 REQUEST_URI 环境变量(它不会在 IIS 中)并且它看起来像一个有效的,那么这将转发请求网址。

So long as you are URL rewriting that to a PHP file...

if (isset($_SERVER['REQUEST_URI'])) AND filter_var(trim($_SERVER['REQUEST_URI']), FILTER_VALIDATE_URL)) {

    header('Location: ' . $_SERVER['REQUEST_URI']);

}

This will forward on the request if the REQUEST_URI environmental variable is set (it won't be in IIS) and it looks like a valid URL.

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