Apache – prevent SQLite DB from download

If you are using SQLite for your website as backend database then it is important to prevent others from downloading the entire database, since SQLite is a file then it can be solved by denying access to the file from the web by this .htaccess rule

RewriteEngine On
RewriteCond %{REQUEST_URI} (.*).db [NC]
RewriteRule ^(.*)$ 404.html [R=404,L]

The rule will prevent access to all files with .db in the name, that will prevent download of files like blog.db mydatabase.db etc.

In my example it will redirect to a 404.html page

Your php script is running inside the server and will still have access to your database files as long as it has the correct unix fileaccess