I am setting up a logging system in an app and while testing writing a log to a file using file_put_contents() I noticed it was writing each log to the file twice.
To try to isolate the cause, I wrote the relevant code directly into the entry file (index.php) as follows:
I admit I am no expert when it comes to writing rewrite rules, but my understanding of what I had is that the first rule would be applied if the conditions were met and the second would be applied if they were not. Your version is more concise though.
Regardless, the issue still occurs even with your version.
I’m not sure, but I’ll copy your virtual host and see if I get the same thing. Granted, I am on a different setup than you, I am actually running Apache2 on a Linux box.
First your Rewrite Cond are wrong. You DO NOT want to use [OR} as effectively you are stating if the request is Not a File with Size, or Not a Symbolic Link, or Not a Directory, then run this rule. Nothing can be ALL three of those things.
If you run that again, you will still get two entries. Why? Well, for this you need to look at the access.log file. You will notice there is a GET for index.php and a GET for favicon.ico. If your setup is like mine, you don’t have a favicon.ico, so your Rewrite Rule kicks in and redirects it to index.php which causes a second log entry.
So I created a blank favicon.ico (just right-click create text file, and rename it to favicon.ico removing the .txt extension)
Now, run it again, and you MAY still get two entries. Why? Because your favicon.ico has a size of 0. The !-s means a file WITH SIZE. So you can either create a REAL favicon.ico or you can change your rewrite rule to be !-f like so: