Symfony2:没有 app.php 找不到 404

Symfony2 : 404 Not Found without app.php

这是我在 public_html 目录中的 htaccess :

DirectoryIndex app.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}:: ^(/.+)/(.*)::$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/ [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>

这是 /etc/apache2/sites-available/mydomain_com.conf :

<VirtualHost *>
        ServerAdmin webmaster@mydomain.com
        ServerName  mydomain.com
        ServerAlias www.mydomain.com

        # Indexes + Directory Root.
        DocumentRoot /home/myuser/domains/mydomain.com/public_html
        # DirectoryIndex app.php
        <Directory /home/myuser/domains/mydomain.com/public_html>
            AllowOverride All
            Order allow,deny
            Allow from All
        </Directory>

        # CGI Directory
        ScriptAlias /cgi-bin/ /home/myuser/domains/mydomain.com/cgi-bin/
        <Location /cgi-bin>
                Options +ExecCGI
        </Location>


        # Logfiles
        ErrorLog  /home/myuser/domains/mydomain.com/log/error.log
        CustomLog /home/myuser/domains/mydomain.com/log/access.log combined
</VirtualHost>

这些是结果:

有什么想法吗?

根据您的设置试用此虚拟主机

<VirtualHost 127.0.0.1>
    DocumentRoot "/path/to/yourdomain.com/web/"
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    <Directory "/path/to/yourdomain.com/web/">
        DirectoryIndex app.php
        AllowOverride All
        Order allow,deny
        Allow from all
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ app.php [QSA,L]
        RedirectMatch permanent ^/app\.php/(.*) /
    </Directory>
</VirtualHost>

是否开启了apache的mod_rewrite?如果没有,启用它,重启服务器再试。

a2enmod rewrite
service apache2 restart