2013-05-22 49 views
1

我知道這已被問了很多次,但有些奇怪的事情正在發生在我身上。 Apache的DocumentRoot的指向的symfony /網絡/這是我的web /目錄內的.htaccess:Symfony:htaccess隱藏app.php或app_dev.php

DirectoryIndex app_dev.php 
#DirectoryIndex app.php 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

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

    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 


    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule ^(.*)$ app_dev.php [QSA,L] 
    #RewriteRule ^(.*)$ app.php [QSA,L] 

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
    RewriteRule ^(.*) - [E=BASE:%1] 
    RewriteRule .? %{ENV:BASE}app.php [L] 
</IfModule> 

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

好了,事情是www.example.com/route1/工作和www.example.com/route2/拋出一個錯誤:

Oops! An Error Occurred The server returned a "404 Not Found". Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

雖然www.example.com/app_dev.php/route2/工作正常(還www.example.com/app_dev.php/route1/

幫助?

更新。緩存督促明確拋出這個錯誤(我以前從來沒有嘗試過,我正在開發):

[Doctrine\Common\Proxy\Exception\UnexpectedValueException] The type hint of parameter "userRoles" in method "addRole" in class "MyProject\PanelBundle\Entity\User" is invalid.

[ReflectionException] Class Maycol\BlogBundle\Entity\Role does not exist

回答

6

這是爲我工作了的.htaccess:

DirectoryIndex app.php 
#DirectoryIndex app_dev.php 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # Redirect to URI without front controller to prevent duplicate content 
    # (with and without `/app.php`). Only do this redirect on the initial 
    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an 
    # endless redirect loop (request -> rewrite to front controller -> 
    # redirect -> request -> ...). 
    # So in case you get a "too many redirects" error or you always get redirected 
    # to the startpage because your Apache does not expose the REDIRECT_STATUS 
    # environment variable, you have 2 choices: 
    # - disable this feature by commenting the following 2 lines or 
    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the 
    # following RewriteCond (best solution) 
    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
    #RewriteRule ^app_dev\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L] 
    RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L] 

    # If the requested filename exists, simply serve it. 
    # We only want to let Apache serve files and not directories. 
    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 


    RewriteCond %{REQUEST_FILENAME} -f 
    #RewriteRule ^(.*)$ app_dev.php [QSA,L] 
    RewriteRule ^(.*)$ app.php [QSA,L] 

    # The following rewrites all other queries to the front controller. The 
    # condition ensures that if you are using Apache aliases to do mass virtual 
    # hosting, the base path will be prepended to allow proper resolution of the 
    # app.php file; it will work in non-aliased environments as well, providing 
    # a safe, one-size fits all solution. 
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
    RewriteRule ^(.*) - [E=BASE:%1] 
    #RewriteRule .? %{ENV:BASE}app_dev.php [L] 
    RewriteRule .? %{ENV:BASE}app.php [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    <IfModule mod_alias.c> 
     # When mod_rewrite is not available, we instruct a temporary redirect of 
     # the startpage to the front controller explicitly so that the website 
     # and the generated links can still be used. 
     #RedirectMatch 302 ^/$ /app_dev.php/ 
     RedirectMatch 302 ^/$ /app.php/ 
     # RedirectTemp cannot be used instead 
    </IfModule> 
</IfModule> 
+0

由於某種原因'RewriteRule^app \ .php(/(.*)| $)%{CONTEXT_PREFIX }/$ 2 [R = 301,L]'只適用於'/ app.php /'個案,而不是'app.php'。我不得不復制這些行,而是添加一個'RewriteRule^app \ .php $%{CONTEXT_PREFIX}/[R = 301,L]'條目。不知道爲什麼作爲正則表達式的作品! – PeterB

+0

你能顯示你的最終文件嗎? 我無法在生產服務器上工作(app.php) – InsaurraldeAP

0

此錯誤是不是在Apache/htaccess的關係。這個404錯誤頁面是symfony本身的默認頁面!

Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused. 

沒有路線匹配/路線2。檢查你的路由是這樣的:

php app/console router:debug 

要檢查它更快使用grep或FINDSTR(Windows)中

php app/console router:debug | grep route2 

也請檢查您的路線不僅是在開發環境配置(即只在routing_dev .yml)!

php app/console router:debug --env=prod 

請...

php app/console cache:clear --env=prod 

清除脾淋巴細胞緩存...,並檢查你的日誌文件,如果有未捕獲的異常訪問頁面時導致404頁顯示。例如,您可以使用此命令查看生產日誌文件中的實時更改。

tail -f app/logs/prod.log 
+0

,我可以看到路徑2與路由器:調試(/路徑2 /),似乎是完全一樣/ ROUTE1 /(除該名稱),另外,/app_dev.php/route2/的作品。 –

+0

請檢查路由器:debug --env = prod ... app.php只使用routing.yml,app_dev.php也加載routing_dev.yml。如果路由僅在routing_dev.yml中,則不會在生產環境中可用。 – nifr

+0

更新了我的答案。 – nifr

相關問題