2015-12-02 109 views
1

如何使用.htaccess将任何.css文件重定向到我的服务器上的页面/控制器?.htaccess mod_rewrite将所有css重定向到页面/控制器

目前,我有以下规则:

# 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] 

我现在想要的任何.css文件重定向到e.g http://127.0.0.1/asset/css?file=stylesheet.css。我尝试了以下方法,但收到404.

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

回答

1
#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] 
相关问题