使用.htaccess隐藏URL的一部分

时间:2016-12-07 23:51:09

标签: php apache .htaccess

我有一个自动生成的网址。示例:

https://domain.com/folder/login/confirm.php?data=ujOeNXV3cVxuljf/username

这个URL是由moodle平台上的用户注册自动生成的,我想更改它,以便不显示最终参数。像这样:

https://domain.com/folder/login/confirm.php

https://domain.com/folder/login

我怎么能在我的.htaccess中这样做?我有Apache WS 2.4和Ubuntu服务器。

1 个答案:

答案 0 :(得分:0)

您是说您不希望他们在地址栏中看到令牌吗?

你可以做的是在confirm.php中,如果它作为GET请求进入,则将其重新发送回confirm.php作为POST。它只会在地址栏中显示,然后才会在处理时显示

这样的事情

<?php

if (isset($_GET["data"]){
$url = 'https://domain.com/folder/login/confirm.php';
$data = array('data' => $_GET["data"]);



// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);

} else {

// if it's not set then you continue processing

}
?>
相关问题