2014-04-15 35 views
0

我有我的本地開發環境加載罰款網站,但炸彈出在生產HTTP Error 500: Internal server error。我無權訪問apache error_log,因爲它在共享主機環境中。的.htaccess錯誤500在生產中,而不是在發展。環境瓦爾

我認爲這個問題是在.htaccess Apache的環境變量的設置 - 可能導致某種無限循環?我需要這些,因爲它們被PyroCMS拾取並用於確定特定於環境的設置,如數據庫配置。

<IfModule mod_rewrite.c> 

    # Make sure directory listing is disabled 
    Options +FollowSymLinks -Indexes 
    # disable the Apache MultiViews directive if it is enabled on the server. It plays havoc with URL rewriting 
    Options -MultiViews 
    RewriteEngine on 

    # Automatically determine and set the PYRO_ENV variable 
    RewriteCond %{HTTP_HOST} ^(localhost|local.mydomain.com|mydomain|mydomain.local)$ 
    RewriteRule (.*) $1 [E=PYRO_ENV:development,L] 

    RewriteCond %{HTTP_HOST} ^staging.mydomain.com$ 
    RewriteRule (.*) $1 [E=PYRO_ENV:staging,L] 

    RewriteCond %{HTTP_HOST} ^www.mydomain.com$ 
    RewriteRule (.*) $1 [E=PYRO_ENV:production,L] 

    # Rewrite "domain.com -> www.domain.com" 
    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC] 
    RewriteCond %{HTTP_HOST} (.+)$ [NC] 
    RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC] 
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,E=PYRO_ENV:production,L] 

    # Keep people out of codeigniter directory and Git/Mercurial data 
    RedirectMatch 403 ^/.*/(system/cms/cache|system/codeigniter|system/cms/config|system/cms/logs|\.git|\.hg|db).*$ 

    # 301 permanent redirects for old web site pages 
    RewriteRule ^some/old/path$ /some/new/path [R=301,L] 
    RewriteRule ^some/other/old/path$ /some/other/new/path [R=301,L] 

    # Send request via index.php (again, not if its a real file or folder) 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    <IfModule mod_php5.c> 
      RewriteRule ^(.*)$ index.php/$1 [L] 
    </IfModule> 

    <IfModule !mod_php5.c> 
      RewriteRule ^(.*)$ index.php?/$1 [L] 
    </IfModule> 
</IfModule> 

如果我註釋掉以下行:

RewriteCond %{HTTP_HOST} ^www.mydomain.com$ 
RewriteRule (.*) $1 [E=PYRO_ENV:production,L] 

然後錯誤500消失,而是我得到一個數據庫連接錯誤(如PyroCMS無法檢測到環境)。

通常,我會使用SetEnv指令將環境變量直接設置到vhost配置中。然而,由於這個特定的網站是共享主機,我無法訪問這些。

我該如何解決這個問題?

另一方面,我在下面的部分提供了舊網頁的301重定向到新網頁(這是一箇舊網站的重建)。我的直覺告訴我,即使我解決這個問題,它被設置在靠近.htaccess文件的頂部環境變量將在另一RewriteRule進一步向下匹配.htaccess文件丟失。我在這個想法中糾正了嗎?

回答

0

該解決方案涉及從RewriteRule的標誌刪除L的設置環境。所述L標誌從被處理停止進一步的規則和調用一個無限循環。通過刪除L標誌,這意味着環境已設置並適用於所有進一步的重定向。這也回答了我可以在另一次301重定向之後堅持ENV的問題。

# Automatically determine and set the PYRO_ENV variable 
# We DON'T use the L flag on RewriteRule here as we want it to persist through redirects. 
RewriteCond %{HTTP_HOST} ^(localhost|local.mydomain.com|mydomain|mydomain.local)$ 
RewriteRule (.*) $1 [E=PYRO_ENV:development] 

RewriteCond %{HTTP_HOST} ^staging.mydomain.com$ 
RewriteRule (.*) $1 [E=PYRO_ENV:staging] 

RewriteCond %{HTTP_HOST} ^www.mydomain.com$ 
RewriteRule (.*) $1 [E=PYRO_ENV:production]