Search code examples
springspring-mvcstaticresource

Mapping all css resources to a single folder using SpringMVC


Is there any way to map all css resources so that they are all served from /css folder from SpringMVC? Ex. /login/sampleUser/ie.css maps to /css/ie.css

I have been trying using <mvc:resources mapping="/css/**" location="/css/" >, but seems not to work.

Thanks


Solution

  • You can be use the Tuckey Url Rewrite Filter. There you can define complexer rewrite rules.

     <!-- I do not know if this fiter works (correctly), but it should
          demonstrate how it works-->
     <rule>
        <!-- redirect everything that ends with .css
             to resources, with same file name -->
        <from>/(.*)/$.css</from>
        <to type="redirect">/resouces/$1</to>
     </rule>