apache - 防止使用 .htaccess 直接下载 SQLite 文件

标签 apache sqlite .htaccess mod-rewrite protection

我了解 .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/

相关文章:

php - 如何使用 apache dns 服务器而不是 LAN 网络中的 IP 地址访问 xampp 下域名的本地网站?

linux - 我收到 "cannot assign requested address"错误

.htaccess - .htaccess 文件中的变量

javascript - chrome 上预压缩的 gzip 中断,为什么?

php - 我想使用重写规则来清除我的网址

apache - .htaccess mod_rewrite,在某些情况下删除第一段(当它是国家/地区代码时)

apache - 如何使用 systemd 支持编译 Apache httpd 2.4.16?

android - 从 Android SQLite 中的多个表查询?

SQLite 查询日期等于今天

python - 有没有办法判断函数是否在单元测试中执行?