4

I've been working on this for quite a while to no avail.. I've got symfony installed on a shared web-host where I have zero access to change the DocumentRoot to the web/ folder so that is not an option to me...

I've written my htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^$ web/app.php [QSA]
RewriteRule ^(.*)$ web/app.php/$1 [QSA, L]

I have also tried this with RewriteBase web/ and RewriteBase /web/ to no avail.

With this, symfony is working.. I can login, I can do all of that... Only problem is, none of the assets are displaying... Chrome Developer Tools, is telling me it's finding a 404 which is right because it's not reading the /web/ folder as the DocumentRoot..

So, how to fix this issue without re-writing files, or anything.. There's got to be a way to do this with .htaccess only...

mabarroso
  • 659
  • 2
  • 11
  • 23
Justin
  • 2,131
  • 4
  • 24
  • 41
  • you should use the original htaccess provided with symfony and just rewritebase your app. because with that htaccess , all requests directed to static assets are processed with the rewrite rule. where are your rewrite conditions ? – mpm Apr 20 '12 at 21:09

2 Answers2

14

One way would be setting assets_base_urls in app/config.yml e.g

framework:
    #..
    templating:      
        engines: ['twig']
        assets_base_urls: http://your.site.com/web/
Mun Mun Das
  • 14,992
  • 2
  • 44
  • 43
  • Okay that works.. But here's a question for you now.. Say I have 2 domains aimed at the same symfony installation -- same website same everything.. only difference is, one is aimed at app_dev.php (and the documentRoot has been set to /web/ for that domain) but I want the assets to only show: /web/ in them for the other domain not http://your.site.com/web/ how would i do that? just setting the assets_base_urls as web/ breaks it for any that have been set at the httpd level (tried it on my localhost) – Justin Apr 20 '12 at 21:35
  • 2
    figured it out... in my config.yml i did as you said except i made assets_base_urls: web/ then in my config_dev.yml i just put: templating: assets_base_urls: / refreshed both instances, and it works... beautiful ;) – Justin Apr 20 '12 at 21:42
4

Or, you can put a .htaccess file in your DocumentRoot folder and rewrite everything that comes in there to your /web folder accordingly:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /web/$1 [QSA,L]
</IfModule>

With that you get clean URL's (omitting "web" or "app.php") and there is no need to use the assets_base_urls stuff in your config.

j0k
  • 22,600
  • 28
  • 79
  • 90
kvdv
  • 57
  • 1
  • -1.. if you look, this has nothing to do with routing... It has everything to do with assets not showing up properly because of the routing discrepancy... htaccess doesn't fix that, the assets_base_urls option does. Enjoy. – Justin Sep 23 '12 at 22:13