htaccess & Symfony, one single route leads to 404, but works with app_dev.php
<p>I have an admin area where I login as described <a href="http://symfony.com/doc/current/cookbook/security/form_login_setup.html" rel="nofollow">here</a>.
This form works in dev enviroment, but when I switch to production the /admin route returns a 404.</p>

<p>The Controller (404 when not using app_dev.php):</p>

<pre><code>/**
 * @Route("/admin", name="mainPage")
 */
public function indexAction(Request $request)
{
    return $this-&gt;render('admin/index.html.twig', array());
}
</code></pre>

<p>My .htaccess in /web (removed comments for readability)</p>

<pre><code>DirectoryIndex app.php
&lt;IfModule mod_negotiation.c&gt;
    Options -MultiViews
&lt;/IfModule&gt;

&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]


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


RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]


RewriteRule ^ %{ENV:BASE}/app.php [L]
&lt;/IfModule&gt;

&lt;IfModule !mod_rewrite.c&gt;
    &lt;IfModule mod_alias.c&gt;
        RedirectMatch 302 ^/$ /app.php/
    &lt;/IfModule&gt;
&lt;/IfModule&gt;
</code></pre>

<p>And finally, my 000-default.conf</p>

<pre><code>DocumentRoot /var/www/html/web

&lt;Directory /var/www/html/web&gt;
    AllowOverride All
    Allow from All
&lt;/Directory&gt;
</code></pre>

<p>Where is the error? The <code>/admin/login</code> route shows the login form. After the login I am moved to <code>admin/</code> (with 404), but when I enter another address manually that is protected it works (e.g. <code>admin/setup/prices</code>) as I am actually logged in.</p>

<p>Changing the route from <code>/admin</code> to <code>/admin/start</code> for example does not change anything.</p>

<p>If you need the security.yml:</p>

<pre><code># To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:

encoders:
  Symfony\Component\Security\Core\User\User: plaintext
  AppBundle\Entity\User: bcrypt

# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
    in_memory:
        memory: ~
    our_db_provider:
        entity:
            class: AppBundle:User
            property: username

access_control:
    - { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin, roles: ROLE_ADMIN }
firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: ~
        # activate different ways to authenticate

        http_basic: ~
        # http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate

        provider: our_db_provider

        form_login:
            login_path: login_route
            check_path: login_check
            csrf_token_generator: security.csrf.token_manager
            use_referer: true
        logout:
            path:   logout_route
            target: mainPage
        # http://symfony.com/doc/current/cookbook/security/form_login_setup.html
</code></pre>

<p>UPDATE
I see now that <code>/admin</code> is actually called but get 301 to <code>/admin/</code></p>

<p>So I think the issue is with this line from the htaccess:</p>

<pre><code>RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
</code></pre>

<p>Changing the route in the controller to <code>/admin/</code> does not help though.</p>