I have the following code which takes a url like ‘www.example.com/foo’ and rewrites it to ‘www.example.com/html/foo.php’
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^([^\.]+)$ html/$1.php [NC]
I want to modify this such that if the rewritten url: ‘www.example.com/html/foo.php’ doesn’t exist, the url is rewritten to ‘www.example.com/html/fallback.php?query=foo’
I’ve been going around in circles for hours. Any solutions?
You can try and do the file exists check first (using
-f) then afterwards, do the rewrite that you have: