找不到没有 app_dev.php 的路线

Cannot found the route without the app_dev.php

当我这样访问我的网站时:

example.com/

example.com/app_dev.php

效果不错。

但是当我尝试去不同的路线时

example.com/api/route/option

我收到错误 404,但是当我转到

example.com/app_dev.php/api/route/option

工作正常。

这是我的 .htaccess

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    RewriteRule ^app_dev.php - [L]
    RewriteRule ^app.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    #RewriteRule ^(.*)$ app.php [QSA,L]
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>

这是我的虚拟主机

<VirtualHost *:80>
    ServerName example.com
    ServerAdmin my_mail
    DocumentRoot /var/www/html/example/web/
        DirectoryIndex app_dev.php
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

有想法了吗?

谢谢!

您的虚拟主机文件未启用覆盖,这意味着您的 .htaccess 文件未被读取。尝试将此添加到您的虚拟主机文件:

<Directory /var/www/html/example/web/>
    AllowOverride None
    Order Allow,Deny
    Allow from All
</Directory>

您可能还想查看此处记录的其他设置选项:http://symfony.com/doc/current/setup/web_server_configuration.html