Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 on shared hosting

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...

like image 388
Justin Avatar asked Dec 01 '22 22:12

Justin


2 Answers

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/
like image 53
Mun Mun Das Avatar answered Mar 10 '23 21:03

Mun Mun Das


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.

like image 35
kvdv Avatar answered Mar 10 '23 19:03

kvdv