Massimiliano
Massimiliano

Reputation: 1

Symfony urls without app.php

I have my symfony app in production env but I can't understand why it doesn't run without app.php. For example if I use mydomainname I can see the home page, but the other routes go in error 404 not found, but if I digit for example the other routes using app.php (mydomainname/app.php/register) it runs perfectly. My httpd.conf is:

ServerRoot "/etc/httpd"

Listen 80

LoadModule rewrite_module modules/mod_rewrite.so

Include conf.modules.d/*.conf

User myuser
Group psacln

ServerName mydomainname:80

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/vhosts/myexample.com/httpdocs/web"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>


<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf
GracefulShutDownTimeout 3
AddOutputFilter INCLUDES .shtml
AddType text/html .shtml
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<VirtualHost *:80>

        CustomLog /var/log/httpd/myexample.com-access.log combined
    ErrorLog /var/log/httpd/myexample.com-error.log
        ServerName myexample.com
    ServerAlias mydomainname
        DocumentRoot /var/www/vhosts/myexample.com/httpdocs/web
    <Directory /var/www/vhosts/myexample.com/httpdocs/web>
                DirectoryIndex app.php

        AllowOverride None
                Order Allow,Deny
                Allow from All
            <IfModule mod_rewrite.c>
                  Options -MultiViews
                  RewriteEngine On
                  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
                  RewriteRule ^ /app.php [L]
            </IfModule>

    </Directory>       
</VirtualHost>

In the error_log file i have for the route register for example:

[Tue May 02 16:45:55.666829 2017] [rewrite:trace3] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d4006440/initial] applying pattern '^(.*)$' to uri '/register/', referer: h t t p s : //mydomainname/
[Tue May 02 16:45:55.666870 2017] [rewrite:trace4] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d4006440/initial] RewriteCond: input='mydomainname' pattern='^mydomain\\.com$' [NC] => not-matched, referer: h   t t p s : //mydomainname/
[Tue May 02 16:45:55.666886 2017] [rewrite:trace1] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d4006440/initial] pass through /register/, referer: h t t p s : //mydomainname/
[Tue May 02 16:45:55.670388 2017] [rewrite:trace2] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d401c1a0/initial/redir#1] init rewrite engine with requested uri /error_docs/not_found.html, referer: h   t  t p  s : //mydomainname/
[Tue May 02 16:45:55.670403 2017] [rewrite:trace3] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d401c1a0/initial/redir#1] applying pattern '^(.*)$' to uri '/error_docs/not_found.html', referer: h t t p s:// mydomainname/
[Tue May 02 16:45:55.670410 2017] [rewrite:trace4] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d401c1a0/initial/redir#1] RewriteCond: input='mydomainname' pattern='^mydomain\\.com$' [NC] => not-matched, referer: https://mydomainname/
[Tue May 02 16:45:55.670414 2017] [rewrite:trace1] [pid 29165:tid 140058380187392] mod_rewrite.c(470): [client 132.64.127.101:54785] 132.64.127.101 - - [mydomainname/sid#7f6204b70c60][rid#7f61d401c1a0/initial/redir#1] pass through /error_docs/not_found.html, referer: https://mydomainname/

The mod_rewrite is on because if i run the httpd -M command there is the line:

rewrite_module (shared)

My server is:

Server version: Apache/2.4.6 (CentOS)

What can I do to solve it?

Thanks a lot.

Upvotes: 0

Views: 1053

Answers (1)

Jason
Jason

Reputation: 721

@Massimiliano

I had the same problem once. I rectified by adding .htaccess file on web folder.

Try adding this on .htaccess file
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php/$1 [QSA,L] </IfModule>

REFERENCE LINK HERE.

And virtual host like this.

<VirtualHost *:80> DocumentRoot /var/www/html/symfony_site/web DirectoryIndex app.php <Directory /var/www/html/symfony_site/web > AllowOverride All Allow from All </Directory> </VirtualHost>

For example if I use mydomainname I can see the home page, but the other routes go in error 404 not found, but if I digit for example the other routes using app.php
=> Add an .htaccess file and the issue would be rectified.

Upvotes: 1

Related Questions