2016-02-01 59 views
1

我有一個管理區域,我登錄所述here。 這種形式的工作在開發環境,但是當我切換到生產/管理的路線返回一個404htaccess&Symfony,一個單一的路線導致404,但與app_dev.php

的控制器(404,當不使用app_dev.php):

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

我在.htaccess /網絡(爲便於閱讀,刪除評論)

DirectoryIndex app.php 
<IfModule mod_negotiation.c> 
    Options -MultiViews 
</IfModule> 

<IfModule mod_rewrite.c> 
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] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    <IfModule mod_alias.c> 
     RedirectMatch 302 ^/$ /app.php/ 
    </IfModule> 
</IfModule> 

最後,我的000-default.conf

DocumentRoot /var/www/html/web 

<Directory /var/www/html/web> 
    AllowOverride All 
    Allow from All 
</Directory> 

錯誤在哪裏? /admin/login路線顯示登錄表單。登錄後,我搬到了admin/(含404),但是當我進入另一個地址手動受保護它的作品(如admin/setup/prices),因爲我實際上已登錄。

改變從/admin的路線/admin/start例如不不改變任何東西。

如果需要security.yml:

# 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 

UPDATE 我現在看到/admin實際上是所謂的,但得到301 /admin/

所以我覺得這個問題是這條線從htaccess的:

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

雖然將控制器中的路由更改爲/admin/並沒有幫助。

+1

您是否清除所有緩存? –

回答

0

在prod env'中,也許你可以分享我們關於錯誤的生產日誌嗎?

否則,您是否嘗試制定特定的消防規則?

firewalls: 
    login_firewall: 
     pattern: ^/login$ 
     anonymous: ~ 
    secured_area: 
     pattern: ^/ 
     form_login: ~