2016-01-18 46 views
1

抱歉,我不能想出一个更好的解释短标题使得路由器需要帮助搞清楚为什么我得到403

我有一个小网站,IM使这个简单的路由器。

如果request_uri中有一个点,它将退出,停止breakout。但是当我尝试一个网址,我得到403在我自己的服务器上

为什么要得到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 

http://localhost/https://www.youtube.com/watch?v=j1w87N9MLhM 
http://localhost/banana://ww.sdf.xx/saf 

好像如果有something:在请求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 

为什么?

+0

'$ _SERVER ['REQUEST_URI']'的值? –

+0

您确定该请求正在发送到您的路由器,而不是直接请求资源? –

+0

如果您使用的是Apache的mod_rewrite,那么我会怀疑您的RerouteRule正则表达式不会捕获像':'这样的特殊字符,并且这些请求正常进行。如果这是问题,那么你应该将你的规则改为'RewriteRule。* router.php [QSA]' –

回答

0
$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); 
} 
相关问题