45

I uploaded my symfony2 project to server grove. The main page loads, but all the links are broken. I tried adding app.php to the web address. It did work, but:

I have routes like this one:

www.something.com/app.php/something

I want them to be:

www.something.com/something.

I've been reading, and I should put some rewrite rules on the .htaccess.

I found these rules, but they don't seem to work:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
5
  • Francisco Ochoa, look at the log file. app/logs/ where you can find the error. Commented Jun 22, 2012 at 4:09
  • is mod_rewrite actually enabled? Commented Jun 22, 2012 at 5:27
  • thanks Inori. It's a nice tip ;). I checked it and yes, it's enabled. Commented Jun 22, 2012 at 12:44
  • 1
    @Blueblazer172 symfony.com/doc/current/setup/web_server_configuration.html. If this is not solving your problem please open a new question. Commented Feb 22, 2017 at 12:01
  • I agree. I can't think of any change in Symfony since 2012 that would need to any change to the accepted answer. Commented Feb 22, 2017 at 14:19

5 Answers 5

59
+50

Try this in your .htaccess file (inside the web directory):

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^app_dev.php - [L]
    RewriteRule ^app.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Change below before deploying to production
    #RewriteRule ^(.*)$ /app.php [QSA,L]
    RewriteRule ^(.*)$ /app_dev.php [QSA,L]
</IfModule>
Sign up to request clarification or add additional context in comments.

5 Comments

I added it but when I went to www.something.com, it says that there was an error...
did you remove everything else in the file?
If anyone else gets the 400 bad request sent error from apache try adding a slash to the rewrite i.e. RewriteRule ^(.*)$ /app_dev.php [QSA,L]
this suggestions just costed me alot of time, getting an error, Options not allowed here
When I deploy to production (commenting RewriteRule ^(.*)$ /app_dev.php [QSA,L] and uncommenting RewriteRule ^(.*)$ /app.php [QSA,L]) it gives me an error. If I leave it like this solution, it works, but it redirects to app_dev.php :( Any help?
26

To improve upon whistlergreg's answer, I added a line so that the bundles folder is not broken. This will make sure external resources such as images are not broken.

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^/web/app_dev.php - [L]
    RewriteRule ^/web/app.php - [L]

    # Fix the bundles folder
    RewriteRule ^bundles/(.*)$ /web/bundles/$1  [QSA,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    # Change below before deploying to production
    #RewriteRule ^(.*)$ /web/app.php [QSA,L]
    RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
</IfModule>

Comments

4

You don't have enabled rewrite module. This code is executed if mod_rewrite.c is enabled. You must only enable mod_rewrite in apache2. http://www.unixmen.com/how-to-enable-and-disable-apache-modules/

For example in Ubuntu:

sudo a2enmod rewrite
sudo service apache2 restart

Comments

0

Also, ... remember to uncomment (if commented) the apache configuration:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

MacOsX

/private/etc/apache2/httpd.conf

Comments

0

You can try giving the full path to your assets(full url). I had the same issue when I deployed my first symfony application

My root directory (public_html folder in most of the case).htaccess file looks like this

Options +FollowSymLinks +ExecCGI

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^projectName/ /projectName/web/app.php/%{REQUEST_URI} [L,NC]

Comments

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.