手动输入URL重定向的标准方法

时间:2013-12-04 04:25:29

标签: php security url

因此,我想知道您的专业人员如何通过不允许用户手动将网址输入某个文件夹(例如website.com/images/)并查看目录列表来保护您的网站。我一直在使用的方法是放置一个index.php文件并使用这个代码,它只是将用户带回主页面。但我觉得这可能是一种更简单的方法。可能是服务器端?

<?php
ob_start();
/* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: ../index.php');
exit;
?>

1 个答案:

答案 0 :(得分:2)

使用htaccess阻止直接访问

创建.htaccess文件添加此Options -Indexes行。将其添加到项目根路径

这些链接可能会对您有所帮助 1. deny directory listing with htaccess 2. http://viralpatel.net/blogs/htaccess-directory-listing-enable-disable-allow-deny-prevent-htaccess-directory-listing/