奇怪的行为 - 允许访问domain.in/file/file

时间:2012-12-21 03:59:11

标签: php html

我在网站上观察到这种奇怪的行为。

我的网络服务器上有以下目录结构

root
login.php
contact.php
myaccount.php
.
.

当我在网址中键入地址时为 http://www.domain.in/contact.php如预期的那样,我在屏幕上显示了我的contact.php。 但是,当我尝试输入以下地址作为网址.. http://www.domain.in/contact.php/myaccount.php在这里,我希望从下面发生一些事情:

1)  a 404 page to be displayed
2)  a redirect to contact.php 

但相反,页面myaccount.php会被渲染,而不是以我希望的方式呈现。

我基本上认为如果我可以使用htacess文件来阻止这种情况,但是我无法弄清楚任何可以适用于这种情况的规则。

欢迎任何帮助。

1 个答案:

答案 0 :(得分:0)

忽略我的最后一个答案,没有完全阅读这个问题。

尝试将此添加到myaccount.php

的顶部
 <?php
 $host = $_SERVER['HTTP_HOST'];
 $self = $_SERVER['PHP_SELF'];
 $query = !empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
 $url = !empty($query) ? "http://$host$self?$query" : "http://$host$self";
 $redirect = '<meta http-equiv="refresh" content="4;url=http://www.domain.in/contact.php">';
 if ($url=="http://www.domain.in/contact.php/myaccount.php") echo $redirect;
 // The Rest of the page here
 ?>