Php 做一个路由器,需要帮忙弄清楚我为什么得到403

Php 做一个路由器,需要帮忙弄清楚我为什么得到403,php,Php,对不起,我想不出一个更好的简短解释标题 我有这个简单的路由器为小网站即时通讯制作 如果请求uri中有一个点,它将退出以停止断开。但当我尝试url时,我在自己的服务器上得到403 为什么a得到403?我的strpos应该能抓住这个 $request = $_SERVER['REQUEST_URI']; $params = explode('/', $request); if (strpos($request, '.') !== false) { //breakout attempt } if

对不起,我想不出一个更好的简短解释标题

我有这个简单的路由器为小网站即时通讯制作

如果请求uri中有一个点,它将退出以停止断开。但当我尝试url时,我在自己的服务器上得到403

为什么a得到403?我的strpos应该能抓住这个

$request = $_SERVER['REQUEST_URI'];
$params = explode('/', $request);

if (strpos($request, '.') !== false) {
//breakout attempt
}

if (!file_exists(sprintf('pages/%s.php', $params[1]))) {
//requested page does not exists, throw or display error
    error();
} else {
    include sprintf('pages/%s.php', $params[1]);
}
现在,它捕捉到了如下URL

http://localhost/asfasg/asfass.sg
http://localhost/www.hello.se
http://localhost/asfasg/dsgsdg/fas.asgas
但是

如果它在请求uri中有
某物:
,则会出现这种情况

You don't have permission to access /https://www.youtube.com/watch on this server.
Apache/2.4.9 (Win64) PHP/7.0.2RC1 Server at localhost Port 80

为什么?

服务器['REQUEST\u URI']的值?你确定请求被发送到路由器,而不是直接发送到请求的资源吗?如果你使用apache的mod\u rewrite,那么我怀疑你的重路由规则正则表达式没有捕捉到一些特殊字符,如
,这些请求正常进行。如果这是一个问题,那么您应该将规则更改为
RewriteRule.*router.php[QSA]
服务器['REQUEST\u URI']的值。您确定请求是发送到您的路由器而不是直接发送到请求的资源吗?如果您使用的是apache的mod\u rewrite,然后我怀疑您的RerouteRule正则表达式没有捕获一些特殊字符,如
,这些请求将正常进行。如果这是问题所在,那么您应该将规则更改为
RewriteRule.*router.php[QSA]
You don't have permission to access /https://www.youtube.com/watch on this server.
Apache/2.4.9 (Win64) PHP/7.0.2RC1 Server at localhost Port 80
$request = "http://localhost/https://www.youtube.com/watch?v=j1w87N9MLhM";
$params = explode('/', $request);

//you want the last index which should be the filename
$filename = array_pop($params);

if (strpos($filename, '.') !== false) {
//breakout attempt
}

if (!file_exists(sprintf('pages/%s.php', $filename))) {
//requested page does not exists, throw or display error
    error();
} else {
    include sprintf('pages/%s.php', $filename);
}