1

When using cssrewrite I am getting the incorrect paths. It works fine when using the app_dev.php or app.php in the URL, for example, mysite.com/site/app.php/login will correctly function. However, using mysite.com/site/login will not work.

When viewing the CSS files I see the following while accessing mysite.com/site/app.php/login:

 src: url('../../bundles/acmetest/font/fontawesome-webfont.eot?#iefix&v=3.2.1')

The correct path when viewing mysite.com/site/login should be:

 src: url('../bundles/acmetest/font/fontawesome-webfont.eot?#iefix&v=3.2.1')

Here is my htaccess file:

DirectoryIndex app.php
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]
    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

Is there a way to configure the production environment to know that its path is /, not app.php/ so that it correctly configures the cssrewrite paths?

Here is my Twig configuration for assetic:

{% block stylesheets %}
    {% stylesheets
        'bundles/acmetest/css/bootstrap.min.css'
        'bundles/acmetest/css/jquery-ui-1.10.3.custom.min.css'
        'bundles/acmetest/css/jquery.iphone.toggle.css'
        'bundles/acmetest/css/font-awesome.css'
        'bundles/acmetest/css/glyphicons.css'
        'bundles/acmetest/css/halflings.css'
        'bundles/acmetest/css/retina.min.css'
        'bundles/acmetest/css/style.css'
    filter='cssrewrite'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
{% endblock %}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • do you have `use_controller` set to `true` in production?! how did you install/symlink/dump your assets? `assets:install web` ? with/without `--symlink` ? with `--env=prod` ? where/how do you configure your asset collection to use the cssrewrite filer - `twig` template? `assetic.assets` configuration? – Nicolai Fröhlich Sep 04 '13 at 08:21
  • use_controller: false in production assets:install web --symlink for install I have updated my original post with my twig template configuration. – user1973496 Sep 04 '13 at 13:35

1 Answers1

0

Before you proceed - read this answer carefully ...


There are actually two possible causes that come to my mind right now.

At first - the cssrewrite filter does not work with the @Bundle-syntax. (documentation reference)

You have to include your stylesheets like this in a twig template:

{% stylesheets 'bundles/my/css/style.css' filter='cssrewrite' %}
    <link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}

Further in order to dump your assets for production use ...

 app/console assetic:dump --env=prod

... to make sure they are being dumped with the right environment settings. ( reference )

Community
  • 1
  • 1
Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • Yes and this works just fine. However once I use mod_rewrite to hide app.php (using e.g.: www.mysite.com/test/login vs www.mysite.com/test/app.php/login) it no longer works. It is re-writing basing off the app.php being part of the URI. Even though it is not being used in production. This is both the same for production & development environments. They both work fine until I use mod-rewrite to hide the application path. – user1973496 Sep 04 '13 at 13:39
  • edited my answer with another hint to the probably best answer on stackoverflow regarding this topic. – Nicolai Fröhlich Sep 04 '13 at 13:51