I wanted to include PHP in my css files, but I don't want to go site-wide and change the URL. Is it possible, using HTACCESS, to serve style.php when style.css is requested? Here's what I tried so far:
RewriteRule /_css/style.css /_css/style.php
Or, better yet: Allow me to keep the extension but have HTACCESS treat it like a PHP file? I'm not very knowledgeable with HTACCESS. Thanks for the help.
You can do it this way
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^_css/([^/]+)\.css$ /_css/$1.php [L]
This rule will match every url like /_css/FILENAME.css if this is not an existing css file (only matching virtual files). If matched, then rewrites to /_css/FILENAME.php
Also, don't forget to enable mod_rewrite if not already done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With