Symfony looks to be looking for assets in a relative location based on the url path I navigate to. The assets load and are applied correctly when I navigate to a "first-level" path such as example.com/mpre
, example.com/test
, example.com/foo
, but then all of my assets 404 when I navigate to a "second-level" url such as example.com/mpre/test
, example.com/test/foo
, example.com/foo/bar
. Why is this? Is there a way to get the framework to look in one spot for the assets regardless of the url?
I have 2 urls
example.com/mpre
example.com/mpre/test
My assets (css, js) load fine on the first url, example.com/mpre
, but then all of them 404 when I navigate to the second url, example.com/mpre/test
When I go into the inspector on each page to see the path to the assets, I see the following:
example.com/bundles/app/css/023f7f6_style.css_4.css //example.com/mpre 200 OK response
example.com/mpre/bundles/app/css/c8b625f_style.css_3.css //example.com/mpre/test 404 Not Found response
In config.yml
I have the following line for assetic:
assetic:
write_to: %kernel.root_dir%/../web/bundles/app/
Additional Information
- I am not using the
cssrewrite
filter
Edit 1
- I installed Symfony 2.3 via composer
Im including the css in base.html.twig and using assetic to compile them
{% stylesheets '@AppBundle/Resources/assets/css/bootstrap_loader.css.scss' '@AppBundle/Resources/assets/css/stately/*' '@AppBundle/Resources/assets/css/bootstrapValidator.min.css' '@AppBundle/Resources/assets/css/style.css.scss' '@AppBundle/Resources/assets/css/learners.css' %}
The paths are standard routes. Each path corresponds to a controller action which renders a view
Here is what the view looks like when the assets 404
- Here is the dump of
./app/console config:dump-reference assetic
Default configuration for extension with alias: "assetic"
assetic: debug: %kernel.debug% use_controller: enabled: %kernel.debug% profiler: false read_from: %kernel.root_dir%/../web write_to: %assetic.read_from% java: /usr/bin/java node: /usr/bin/node node_paths: [] ruby: /home/ubuntu/.rvm/rubies/ruby-2.0.0-p195/bin/ruby sass: /home/ubuntu/.rvm/gems/ruby-2.0.0-p195/bin/sass variables:
# Prototype
name: []
bundles:
# Defaults:
- FrameworkBundle
- SecurityBundle
- TwigBundle
- MonologBundle
- SwiftmailerBundle
- AsseticBundle
- DoctrineBundle
- SensioFrameworkExtraBundle
- AppBundle
- LswMemcacheBundle
- WebProfilerBundle
- SensioDistributionBundle
- SensioGeneratorBundle
assets:
# Prototype
name:
inputs: []
filters: []
options:
# Prototype
name: []
filters:
# Prototype
name: []
workers:
cache_busting:
enabled: false
twig:
functions:
# Prototype
name: []
Edit 2
I've found the source of the problem. The link path was relative, so I changed it to use the baseUrl. <script src="{{ app.request.baseUrl }}/bundles/app{{ asset_url }}"></script>
and everything works great.