.htaccess mod_rewrite redirect all css to page/controller

How do I redirect any .css file to a page/controller on my server using .htaccess?

I currently have the following rule:

# Remove index.php from Codeigniter
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

I now want any .css file to be redirected to e.g http://127.0.0.1/asset/css?file=stylesheet.css. I have tried the following but receive a 404.

RewriteRule .*\.(css)$ /asset/css?file=$0 [NC,L]

Answers


#Rule for css
RewriteRule ([^.]+)\.css$ asset/css?file=$1.css [NC,L]
#end of css rule
# Remove index.php from Codeigniter
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Need Your Help

Regex to validate a number for length and start digits

c# regex validation

I'm looking for a regex that will validate a number.

Django model pre save for custom ManyToManyField

python django django-models django-forms

I have a model with a many-to-many relationship. In a pre_save signal i want to preprocess the instance data: