javascript - 使用 URL 的简单页面重定向

标签 javascript php jquery url-redirection

我希望我的 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/

相关文章:

javascript - 将 SVG 元素转换为 img

php - 如何将表单中的值存储到 mySQL 数据库中?

php - 嵌套子查询中的 MySQL 变量

回调后 jquery 不工作

javascript - 如何防止数字字段上的特殊字符复制粘贴

javascript - 使用 Meteor 对集合中的对象进行分组

javascript - 我可以创建一个同时适用于 HTTP 和 HTTPS 的 javascript 文件吗

php - 未捕获的语法错误 : Unexpected token ILLEGAL

php - 无法加载请求的文件: templates/header. php

jquery - 同级 css 选择器没有改变