I’m trying to make sure a redirect rule doesn’t match if the file doesn’t exist. For example, example.com/blog
should match if blog.php exists otherwise not. The problem is with a url like example.com/blog/a/test
it matches example.com/blog.php
and finds the file. It should’ve attempted to find blog/a/test.php
.
Here’s my code:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L]
And here’s the logs
add path info postfix: D:/ProjectLocation/blog -> D:/ProjectLocation/blog/a/test-post, referer: https://example.com/blog/a/test-post
strip per-dir prefix: D:/ProjectLocation/blog/a/test-post -> blog/a/test-post, referer: https://example.com/blog/a/test-post
applying pattern '^(.+)$' to uri 'blog/a/test-post', referer: https://example.com/blog/a/test-post
RewriteCond: input='D:/ProjectLocation/blog.php' pattern='-f' => matched, referer: https://example.com/blog/a/test-post
rewrite 'blog/a/test-post' -> 'blog/a/test-post.php', referer: https://example.com/blog/a/test-post
I tried adding AcceptPathInfo Off
to the top of the file because I think this flag controls this behavior but it didn’t make any difference.