Reputation: 27
I am working on a PHP application that I'd like to regulate file serving for various reasons. I need all requests to be passed to my index.php
file. Currently I have this working for all requests except files and directories that exist. For security reasons and content protection I'd like to perform some challenges before serving files to the browser using readfile
and I'd like to completely block directory access which will just show a 404 page for files and directories I don't want users to see (i.e., private content, php scripts, etc.).
This is my current HTACCESS file:
# Turn On Rewrite Engine
RewriteEngine On
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_URI} !^.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I don't no what to do with the RewriteCond
that is causing files to be mapped to the index.php
file if they don't exists. I'd like them to remap there whether or not they do exist.
For example, navigating to "http://www.example.com/some/real/script.php" would redirect the path to PHP regardless if it exists or not. Thanks guys in advance.
Upvotes: 0
Views: 1699
Reputation: 401
This one worked for me
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !/folder
RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]
</IfModule>
Upvotes: 2