I've got a Web site with a bunch of docs and pdfs in /foo/bar/
Directory browsing is turned off, so you have to know the specific URL/URI combo to get the document. I'd like to find a way of redirecting ALL requests to /foo/bar/ to a php page that checks their auth cookie is set and, if so, gets their file. Of course, I also need the rule not to trigger if the request is for auth_test.php
, in order to prevent looping. I have been fighting with the .htacess in /foo/bar/ and I simply cannot get this to work. mod_rewrite makes regexes look clear and obvious by comparison.
Here is my current .htaccess file (in /foo/bar/):
RewriteEngine On
RewriteRule !^auth_test\.php$ /foo/bar/auth_test\.php?q=$1 [R=301,L]
This successfully works for request to /foo/bar/auth_test.php
, but a request to /foo/bar/something sends me to /foo/bar/auth_test.php?q=
It's like $1 isn't even picked up. Additionally, this rule seems to be ignored if the file exists, so requests to /foo/bar/mydocumnent.doc result in the user being prompted to download the requested file. I've even tried to add
RewriteCond %{REQUEST_FILENAME} -f
to prevent this, but that doesn't seem to work. I'm totally at a loss here. Any suggestions?