问题
If I go to this URI
/app_dev.php/css/eabd201_jquery.ui.theme_15.css
it gives me that CSS file, which is what I would expect, but if I go to this URI,
/app_dev.php/css/images/ui-icons_222222_256x240.png
I get this error:
No route found for "GET /css/images/ui-icons_222222_256x240.png"
It seems like there must be a way to tell Symfony not to try to go through routing for /css/*
paths. (I know the file exists.) How might I do that?
Edit: here's my .htaccess
file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
回答1:
I don't know if it's exactly your case but imagine the directory structure:
├── css
│ ├── style.css
├── images
│ ├── foo.png
In style.css
, as soon as you are referencing your images using relative paths like url(../images/foo.png)
, so it can't work if you move style.css
into another directory.
You're using Assetic to render your CSS files so assetic "moves" this CSS file into the /app_dev.php/css
directory which does not really exist and is handled by the app_dev.php
controller. So now, the relative path to the image does not point to the image but to /app_dev.php/images/foo.png
which also does not really exist and is handled by the app_dev.php
controller.
Hopefully it's a really common problem and there is a built-in solution: the cssrewrite
filter.
You can either add it to your {% stylesheet %}
tags:
# app/config/config.yml
assetic:
# ...
filters:
cssrewrite: ~
{# your template #}
{% stylesheet 'bundles/foo/css/style.css' filter='cssrewrite' %}
Or apply it to every CSS file:
# app/config/config.yml
assetic:
# ...
filters:
cssrwrite:
apply_to: \.css$
It will take care of rewriting this kind of paths for your.
来源:https://stackoverflow.com/questions/10397450/symfony2-is-trying-to-feed-my-css-paths-through-routing-but-i-dont-want-it-t