[英]Simple Page Redirect Using URL
I want my index.php to redirect to my welcome/index.html. 我希望我的index.php重定向到我的welcome / index.html。 I know there are so many ways to do it but I want to shorten it just like Facebook does.
我知道有很多方法可以做到,但我想像Facebook一样缩短它。 I want a url based redirection.
我想要一个基于网址的重定向。 I want to redirect index.php to welcome/index.html by using url.
我想通过使用url将index.php重定向到welcome / index.html。
For example: 例如:
example.com to example.com/?url=welcome
//this 'url=welcome' is the index.html of my welcome folder.
Here's the code, according to what I've understood. 根据我的理解,这是代码。 Place it on the very top of
index.php
. 将它放在
index.php
的最顶层。 I'm assuming you're using the domain example.com
我假设您正在使用域
example.com
<?php
$destination = $_GET["url"];
switch($destination) {
case "welcome": // add your destinations here, one per single "case"
case "about":
case "anotherpage":
header("Location: /" . $destination . "/index.html");
break;
default:
echo "Error";
break;
}
?>
Doing this way you can manage which redirects will work and what not, avoinding "evil" usages of your redirect system. 通过这种方式,您可以管理哪些重定向将起作用,哪些不起作用,从而避免重定向系统的“恶意”使用。
Something malicious like example.com?url=http://evilsite.com
will not redirect them to evilsite.com
像
example.com?url=http://evilsite.com
这样的恶意软件不会将它们重定向到evilsite.com
This is probably not the best solution, but it's a good starting point to avoid not wanted redirections. 这可能不是最好的解决方案,但它是避免不想重定向的良好起点。
Not really sure if this would help, but you're welcome to try 不确定这是否会有所帮助,但欢迎您尝试
<?php
if (isset($_GET["url"])) {
$url = $_GET['url'];
header('Location:'.$url);
}
?>
I haven't tried this, but this is what I thought after seeing your post 我没试过这个,但这是我看到你发帖后的想法
somewhere i read using header for redirection is little bit dangerous as header can b changed easily by hacker and hacker can send victim to another location easily. 我使用标题进行重定向读取的地方有点危险,因为黑客可以轻易改变标题,黑客可以轻松地将受害者发送到另一个位置。 so i use javascript location.href function for redirection.
所以我使用javascript location.href函数进行重定向。
<?php
echo "<script>window.location ='http://example.com/welcome/index.html</script>";
?>
if you want to send user to dynamic url from example.com you can set a get variable like. 如果你想从example.com发送用户到动态网址,你可以设置一个get变量。
source address: http//example.com?url= http://example.com/welcome.html destination address: http://example.com/welcome.html 来源地址:http // example.com?url = http://example.com/welcome.html目的地址: http : //example.com/welcome.html
<?php
if(isset($_GET['url']))
echo "<script>window.location ='$_GET[url]'</script>";
else
echo "<script>window.location='http://somewhereelse.com'";
?>
now u can dynamically set url variable in your source address and redirect user wherever you want to 现在,您可以在源地址中动态设置url变量,并在任何地方重定向用户
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.