我希望我的 index.php 重定向到我的 welcome/index.html。我知道有很多方法可以做到这一点,但我想像 Facebook 那样缩短它。我想要一个基于 url 的重定向。我想使用 url 将 index.php 重定向到 welcome/index.html。
例如:
example.com to example.com/?url=welcome
//this 'url=welcome' is the index.html of my welcome folder.
最佳答案
根据我的理解,这是代码。将它放在 index.php
的最顶部。我假设您使用的是域 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;
}
?>
通过这种方式,您可以管理哪些重定向有效,哪些无效,避免重定向系统的“邪恶”用法。
example.com?url=http://evilsite.com
等恶意内容不会将他们重定向到 evilsite.com
这可能不是最好的解决方案,但它是避免不需要的重定向的一个很好的起点。
关于javascript - 使用 URL 的简单页面重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42829433/