Ask your Symfony questions! Pay money and get answers fast! (more info)

App not working unless showing controller in URL Symfony

I'm testing my Symfony 1.4 app in a development server using the following .htaccess file:

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
RewriteEngine On

# uncomment the following line, if you are having trouble
# getting no_script_name to work
RewriteBase /

# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]

# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>



If I do www.example.com/anything it takes me to 404.

I have a route in routing.yml which is for the root address (www.example.com).. and that one works.

It only works if I add the controller file before, for example www.example.com/index.php/login or frontend_dev.php as well

Do you know what could be causing this? it works fine in my local environment when I try it in production mode.

My settings.yml


prod:
.settings:
error_reporting: <?php echo (E_PARSE | E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR | E_USER_ERROR)."\n" ?>
no_script_name: true
logging_enabled: false

dev:
.settings:
error_reporting: <?php echo (E_PARSE | E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR | E_USER_ERROR)."\n" ?>
web_debug: true
cache: false
no_script_name: false
etag: false
logging_enabled: true

Answers (6)

2011-12-20

Ben answers:

do you have apache mod_rewrite installed?
you can check this by making a phpinfo file.

//info.php

<?php
phpinfo();


fxsymfony comments:

mod_rewrite doesn't show there, but I read that it could still be installed, so I'm double checking with the server admin (it's a client's server so I don't have access to much)

2011-12-20

José Nahuel Cuesta Luengo answers:

Have you tried going through Apache's logs to see what is going on under the hood?

That way you might see if there's a typo or configuration error.

Just a wild guess: is the URL a root one (like the www.example.com you used)? or is it something like www.example.com/my-app/ ? Try commenting out the
RewriteBase / directive.


fxsymfony comments:

yes it's a root one.

2011-12-20

Martin Palacio answers:

if you deploy a symfony app under a subdirectory, ex. localhost/myapp, you must:

1) check if mod_rewrite is installed (as stated by Ben)
2) adjust the RewriteBase directive to match your subdirectory name, ex:

RewriteBase /myapp


cheers

2011-12-20

Jakub Zalas answers:

Do you have mod_rewrite turned on? Could you paste your virtual host definition? Do you have "AllowOverride All" in there?

Use RewriteLog to debug your rewrite rules:

RewriteLog "/var/log/apache/rewrite.log"
RewriteLogLevel 3


Adapt path to log file and log level to your needs. "The default level 0 means no logging, while 9 or more means that practically all actions are logged." ([[LINK href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog"]]see docs[[/LINK]]).

<strong>Note</strong>: Don't use this logger on production as it will significantly slow your website down.


2011-12-20

Luis Cordova answers:

also paste your vhost.conf, are you on mediatemple?

you could rule out the stuff with a clean copy of a demo app 1.4, then if that does not fail

then check your project files for a setting that could be presenting the problem.

2011-12-20

Milena Dimitrova answers:

Apart from mod_rewrite installed you need to have in your virtual host configuration:

AllowOverride All
Allow from All

(so that htaccess takes effect)
and

DirectoryIndex index.php index.html

(make sure index.php comes first)

See sample configuration for Jobeet:
http://www.symfony-project.org/jobeet/1_4/Propel/en/01

You probably don't have access to the host configuration but the server admin can do it.