我了解 .htaccess 的基础知识,但坦承自己在 mod_rewrite 方面不是专家。
问题:
我在文档根目录中有一个名为 data.sqlite
的 sqlite db 文件(不,我不能将其移出此处)。该文件由 PHP 文件在内部访问,但是,我想保护该文件不被用户直接在浏览器中键入 db URL 的“下载”。
我过去曾使用 .htaccess 创建漂亮的 URL,并认为使用 mod_rewrite 可以很好地解决我的问题。然而,我的重写规则似乎并没有阻止访问。
.htaccess
Options +FollowSymLinks
Options -multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{http_host} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,NC]
##prevent access to any file data.sqlite by redirecing back to index.php
RewriteRule ^data.sqlite$ index.php [L,NC]
##my other rules follow - not shown here
有什么我在重写时出错的想法吗?我确定这很简单?
编辑:
理想情况下,我想阻止对所有以 .sqlite 结尾的文件的直接 URL 访问,而不仅仅是 data.sqlite
最佳答案
关于“从 开始”。那不是真的!文件必须以“.ht”开头,默认情况下在 Appache 上被阻止。
关于apache - 防止使用 .htaccess 直接下载 SQLite 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4211832/