您好,我已经使用 codeigniter 来开发我的网站,但是当在 google 中搜索我的网站时,google 会显示特定文件夹中文件(pdf)的链接,用户可以直接查看这些文件(pdf)而无需登录。我想限制谷歌直接显示这些文件的链接。
例如:www.mywebsite/myfolder/myfile
请指导我如何实现这一目标。谢谢。
较之前稍作修改answer https://stackoverflow.com/questions/12247040/how-to-restrict-access-to-files-in-a-folder-in-codeigniter/12247430#12247430 :
将 .htaccess 与内容一起放入文件夹中
order deny, allow
deny from all
这将拒绝对该特定文件夹的所有访问。
为了访问文件,在控制器中编写一个带有主体的函数 -
public function index($file_name){
if($this->login()) // login check
if (preg_match('^[A-Za-z0-9]{2,32}+[.]{1}[A-Za-z]{3,4}$^', $file_name)) // validation
{
$file = 'my_path/'.$file_name;
if (file_exists($file)) // check the file is existing
{
header('Content-Type: '.get_mime_by_extension($file));
readfile($file);
}
else show_404()
}
else show_404();
}
然后你必须在配置文件夹中的routes.php文件中添加一些行,如下所示
$route['my_files/(:any)'] = "my_controller/index/$1";
这会将所有请求重定向到 myfiles/bla_bla_bla 到 my_controller/index/bla_bla_bla
认为这可能有帮助:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)