Reputation: 2591
I have multiple css files in a directory (style0.css, style1.css etc..) How can I redirect a request to these css files with htaccess so that a php can process the requested css file.
ex. /styles/style0.css -> /includes/compressor.php?i=style0.css
?
Upvotes: 3
Views: 4930
Reputation: 1967
Add an .htaccess to your css directory with these two lines. You can now add php code to your css files, and it will be processed :
AddHandler application/x-httpd-php .css
php_value default_mimetype "text/css"
Upvotes: 7
Reputation: 140753
RewriteEngine On
RewriteRule ^(.*).css$ /includes/compressor.php?i=$1.css [L]
These .htAccess command activate the RewriteEngine. This will let you analyse the request URL and execute the one you want into the server. The second line take all URL that end with .css and will take the file name to insert it as a parameter (like you wanted in your example).
For example:
http://localhost/styles/style1.css will go to
http://localhost/includes/compressor.php?i=style1.css
The L flag will tell Apache to stop processing the rewrite rules for that request.
Upvotes: 6