Forum Moderators: phranque

Message Too Old, No Replies

ALL Directory requests

whether they exist or not

         

amommy

8:34 pm on Feb 26, 2011 (gmt 0)

10+ Year Member



Hello All
I have been trying this for a few hours now and I know it is something SIMPLE I am missing but I just cannot get it.
I have this
if the file and folder DO NOT exist on the server redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /otherfile.php [L,NC,QSA]

Which I need and need it to take place before any other code. (note the QSA)

I need something to take place AFTER the above ONLY if the file or folder requested DO NOT exist on the server.

If they DO exist on the server I need to redirect all request for them if they do not come from a certain IP

RewriteCond %{REMOTE_ADDR} !^00\.00\.00\.00$

SOMETHING HERE - IF FILE OR FOLDER EXIST

RewriteRule !^index.htm index.htm [R,NC,L]


I have tried many things including
RewriteCond %{REQUEST_FILENAME} -f
and
RewriteCond %{REQUEST_FILENAME} -d
with
RewriteRule !^index.htm index.htm [R,NC,L]

but then the top rule breaks and it redirects all to index.htm
Please help

Thanks

g1smd

10:14 pm on Feb 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to replicate the entire ruleset above the existing set but the new set will have your extra RewriteCond %{REMOTE_ADDR} !^00\.00\.00\.00$ code in it as well as the other modifications.

The more specific code is listed first, and the more general code is listed last.

Start by writing down in longhand, on separate pieces of paper, what you need each function to do.

"Redirect if this is true and that is false"

"Rewrite if this is true and that is true"

etc. Once you have the functionality planned out in detail, and only then, start thinking about code.