htaccess选择性转发
这是一个有点独特的问题,我似乎无法在任何地方找到答案!我是处理 htaccess 文件的新手。这就是我想要做的,让我知道这是否可能:
我试图在有人直接访问某个目录时进行重定向,但是,我的服务器需要能够访问该目录以启动文件下载。
这是我用来完成重定向的方法:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ ../ [NC]
它的工作原理就像一个魅力,但是当我的脚本尝试访问文件系统时,它自然也会被重定向。
这样做的目的是保护文件下载。用户通过保护区访问下载,下载链接类似于 http://example.com/download/superlongidhash< /a>
然后脚本会获取并读取该 URL,制定文件的实际路径并相应地发送 php 标头:
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($path));
header("Content-disposition: attachment; filename=" . basename($path) . "");
readfile($path);
任何帮助将不胜感激:) 如果有更好的方法来执行此操作,请告诉我!
仅供参考,这一切都在 CodeIgniter 框架内
This is somewhat of a unique question that I cant seem to find the answer for anywhere! I am new to playing with htaccess files. Here's what im trying to do, let me know if this is at all possible:
I am trying to redirect when someone access a certain directory DIRECTLY, however, my server needs the ability to access the directory to initiate file downloads.
Here's what I am using to accomplish the redirect:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ ../ [NC]
It works like a charm, however when my script tries to access the filesystem it naturally gets redirected as well.
The purpose of this is protected file downloads. The user's access downloads via a protected area and the download link is similar to http://example.com/download/superlongidhash
This URL is then taken and read by the script, formulates the actual path to the file and sends php header's accordingly:
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($path));
header("Content-disposition: attachment; filename=" . basename($path) . "");
readfile($path);
Any help would be much appreciated :) If there is a better way to do this, let me know!
FYI, this is all within the CodeIgniter framework
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检查 http_referrer 是否适合您的网站。如果不是,您可以将用户重定向到您的主页(或您想要的任何地方)。
看看我发现的这篇关于做你想做的事情的文章。
http://www .dialme.com/m/articles/view/How-to-Prevent-direct-access-to-files-and-folders
我希望这会有所帮助。
You can check the http_referrer is the one for your site. If it's not, you redirect the user to your homepage (or wherever you want).
Take a look into this article I found about doing exactly what you want.
http://www.dialme.com/m/articles/view/How-to-Prevent-direct-access-to-files-and-folders
I hope this helps.