I have a problem with an old project for which I have the following mod_rewrite conditions/rules:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
But .phtml files are being rendered as plain text in the browser.
The problem is that I have some .phtml files within a public directory that are matching the first rewrite condition '-s' (is regular file, with size) and so they're not getting sent to index.php. In fact, the .phtml files are showing as plain text! I need to keep those files there so I can't set deny from all
for that directory because it also contains some images and stuff.
I tried this:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteRule \.phtml$ index.php [NC,L]
But it didn't work because it already met the first rewrite condition, so the first rule got applied (to do nothing).
How can I get around that?
I think that rule and .htaccess is not a condition here. You should configure apache tu use phtml files with php:
then the rule
can be ommited and it should work, because file exists and have size, so apache should handle it like any other PHP file.
edit: If you don't want to serve .phtml files at all, you culd use rewrite like that:
You said: "But it didn't work because it already met the first rewrite condition, so the first rule got applied (to do nothing)."
And that's quite right, because the L flag in rule tells apache that if it is applied, other rules should not be applied.
It is commonly used for redirects and such, but in your case this flag is not needed.
Try this configuration: