Hi gang!
Been a while since I had one of these issues, but I'm on holiday so building something for fun as my office won't allow me to write code anymore :)
I'm playing with a REST-ful API that has a website on the same server and I want to match the first directory and map that to a .php file. I want to ignore everything else, so my static html, php, cs, js etc files remain as is. EG:-
https://example.com/123-abc/ . <-- gets mod_rewritten to https://example.com/myfile.php?q=123-abc
BUT
https://example.com/js/jquery.js <-- does not get mod_rewritten because it's an actual file that really exists
After some googling, thinking and trial and error I came up with this:-
Options +FollowSymLinks
RewriteEngine On
LogLevel alert rewrite:trace6
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /myfile.php?q=$1 [L,QSA]
I believe the RewriteRule is working correctly because the matches that I did want to catch are working.
However, all my javascript, css etc is getting matched and re-written too.
My intention/understanding was that these two lines:-
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
... would prevent from re-writing the existing files and existing directories.
I slept on this to see if I could spot my mistake in the morning, but I can't. I'm hoping someone here can :)
Thanks!
PS - I don't know if it makes a difference, but I haven't put this in .htaccess - I have put it in my apache default-ssl config file.