Javascript 使用URL的简单页面重定向

Javascript 使用URL的简单页面重定向,javascript,php,jquery,url-redirection,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重定向到我的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.

不确定这是否有用,但欢迎您尝试

<?php 
  if (isset($_GET["url"])) {
    $url = $_GET['url'];
    header('Location:'.$url);
  }
 ?>


我没有试过这个,但这是我看到你的帖子后的想法,根据我的理解,这是代码。将其放在
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

<?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;
}

?>

这可能不是最好的解决方案,但这是避免不想要的重定向的一个很好的起点。

在我读到的某个地方,使用头进行重定向有点危险,因为头很容易被黑客更改,黑客可以很容易地将受害者发送到另一个位置。因此我使用javascriptlocation.href函数进行重定向

<?php
echo "<script>window.location ='http://example.com/welcome/index.html</script>";
?>

这真的很危险,因为我可以欺骗用户将他们重定向到不好的地方。示例:
Example.com?url=http://evilsite.com
将它们重定向到
evilsite.com
您可以按原样使用它。但正如@Napolux所说,这是一种非常危险的重定向方式,我收到的反对票就是证明。当然,你可以“清除”或限制将要使用的URL。您可以使用POST,但根据您的示例,您正在使用GET@ChevroletSS忘了问,URL的最终格式是什么?啊,如果是的话,那么我认为我的答案对你没有帮助。我还想在index.html@napoluxb中隐藏.html扩展名,但它实际上并没有回答我的问题@napolux…我应该使用javascript吗?比如在6秒钟后,它会重定向到welcome/index.html,但在地址栏中你能看到的唯一东西是?url=welcome你想要一个JS解决方案还是一个PHP解决方案。在这一点上,问题还不清楚:(只要浏览器地址栏上的输出为?url=welcome,其中一个就足够了)只要浏览器地址栏上的输出为?url=welcome–@Napoluxremove不适当的标记,facebook etcnoted@Gouravbajaj提供指向此项的链接,其中一个就足够了“在我读过的某个地方"是什么让使用javascript更好甚至更安全?请告诉我们您没有得到什么?假设example.com/index.php是您想要重定向的页面。example.com/welcome/index.html是您的登录页面。因此,在index.php页面中,您需要有这样的变量,以便无论何时用户来到index.php页面,都将重定向到欢迎/index.html页面。注意:为了提高安全性,您可以在重定向之前验证您的域。在这种情况下,如果($\u GET['url']==“welcome”)echo“'example.com/welcome/index.php”“”,请更改index.php;删除所有内容并编写下面的代码。从何处立即重定向?现在在index.php中编写if($\u GET['url']==“welcome”)回声“'