logo

$5
App not working unless showing controller in URL

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

fxsymfony | 12/20/11 at 6:53am | Edit


(6) Possible Answers Submitted...

  • avatar
    Last edited:
    12/20/11
    6:57am
    Ben says:

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

    //info.php


    <?php
    phpinfo();

    • 12/20/11 7:11am

      fxsymfony says:

      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)

  • avatar
    Last edited:
    12/20/11
    6:59am
    José Nahuel Cuesta Luengo says:

    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.

    • 12/20/11 7:12am

      fxsymfony says:

      yes it's a root one.

  • avatar
    Last edited:
    12/20/11
    7:01am
    Martin Palacio says:

    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

  • avatar
    Last edited:
    12/20/11
    7:03am
    Jakub Zalas says:

    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." (see docs).

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


  • avatar
    Last edited:
    12/20/11
    7:29am
    Luis Cordova says:

    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.

  • avatar
    Last edited:
    12/20/11
    7:38am
    Milena Dimitrova says:

    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.

This question has expired.





Current status of this question: Community pot