PHP 内联 URL 重定向?
我想知道是否有可能让人们只需输入链接即可:
并在人们访问时让它真正转到真正的链接。
这就是我所拥有的,但我不知道如何实施。
<?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您将 URL 重写为 PHP 文件...
如果设置了
REQUEST_URI
环境变量(它不会在 IIS 中)并且它看起来像一个有效的,那么这将转发请求网址。So long as you are URL rewriting that to a PHP file...
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.