3

I have my application in symfony 2 done.
And now I want to remove the web/app_dev.php/ from the url.

I read about this and after doing this:

php app/console cache:clear --env=prod --no-debug

And add .htaccess:

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>

After this I can use the url: localhost/test/web/ But it's not exactly my goal. I want to remove the web also.

And after this there's another problem. When I'm using localhost/test/web/ to access the page there's some stylesheet missing, but in app_dev.php everything looks good.

My question is, How can I remove the /web/ from the url? And how can I have the stylesheet missing?

2 Answers 2

4

To remove the web you simply have to modify your apache configuration to make web as root directory.

    DocumentRoot /yourpath/www/web
    <Directory /youpath/www/web/>

Exemple of Apache Virtual Host Complete configuration :

<VirtualHost *:80>
    ServerName www.yourdomain.com
    DocumentRoot /yourpath/www/web

    <Directory /yourpath/www/web>
        Options FollowSymLinks
        AllowOverride None
        Require all granted
        Allow from All

        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /app.php [QSA,L]
    </Directory>

    LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/your_site.error.log
    CustomLog ${APACHE_LOG_DIR}/your_site.log combined
</VirtualHost>

In production you should remove app_dev.php and set as root directory symfony web folder

Note: I don't add <IfModule mod_rewrite.c></IfModule> because if you don't have it you want apache to inform you that you are missing this module.

Sign up to request clarification or add additional context in comments.

Comments

2

Apache/mod_rewrite configuration

To remove the /web part you can set RewriteBase additionally

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /web/
    ...

... or set your DocumentRoot directly to the web folder in your apache VirtualHost configuration.

stylesheet issue

The missing stylesheet in the prod environment can be resolved by invoking the assets:install command.

In the dev symfony will serve the files directly from the bundle's Resources/public folders because the default config_dev.yml contains assetic.use_controller: true.

The default production configuration has assetic.use_controller: false for performance reasons. Assets will not be recompiled and served through symfony on every request.

Now the assets in a bundle's Resource folder are not accessible until they are being moved/symlinked to the web folder where your webserver can find them which the assets:install and assetic:dump commands do.

3 Comments

/web problem solved but now cant fix the stylesheet, I run the command php app/console assets:install --env=prod and then i clean the cache and still the same issue. I'm using cssless to generate this stylesheets
Please open a separate question for the stylesheet issue and provide more information. Which files don't get loaded? Only some or all? Where do your files come from (i.e. Bundle/Resources/public )? How do you include them in your template ( i.e. using {{ asset(..) }} or {% stylesheets .. } ? What URL gets generated and returns the 404 error (see firebug/devtools network panel)? Include your assetic configuration for the prod environment aswell please.
I fixed everything, the .htaccess and the missing pictures, but now theres just the icons dont show! I'm using a template with bootstrap icons, and they dont show

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.