2016-08-25 37 views
1

我有一個網站在cPanel上運行,其中wordpress安裝在根目錄中。我還有一個自定義的應用程序,它位於名爲'gallery'的子文件夾中。畫廊子文件夾內是一個'管理員'文件夾。 gallery(無重寫)的根文件夾控制信息的顯示,其中'gallery/admin'的根目錄授予用戶對應用程序的管理訪問權限。路徑結構被重定向和處理(自定義MVC框架),其主要由以下的.htaccess指令涉及:Apache 2.4上的嵌套RewriteRules導致500錯誤

需要所有授予

RewriteEngine On 
RewriteCond %{REQUEST_URI} !\.(jpg|png|bmp|gif|css|js|map|ttf|woff|woff2|svg|eot)$ 
RewriteRule ^(.*)$ controller.php?page=$1 [NC,L,QSA] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ controller.php?page=error&rewritten=1&missing=$1 [NC,L,QSA] 

的WordPress htaccess的定製的壓縮,到期/不同類型的緩存,除了處理傳統的WordPress的東西,如下(在全粘貼):

Options -Indexes 
# BEGIN WordPress 

# Expires Caching (Leverage Browser Caching) 
<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresByType image/jpg "access 2 week" 
ExpiresByType image/jpeg "access 2 week" 
ExpiresByType image/gif "access 2 week" 
ExpiresByType image/png "access 2 week" 
ExpiresByType text/css "access 2 week" 
ExpiresByType application/pdf "access 2 week" 
ExpiresByType text/x-javascript "access 2 week" 
ExpiresByType application/x-shockwave-flash "access 2 week" 
ExpiresByType image/x-icon "access 2 week" 
ExpiresDefault "access 2 week" 
</IfModule> 

# Enable GZIP Compression (compress text, html, javascript, css, xml and so on) ## 
<ifModule mod_gzip.c> 
    mod_gzip_on Yes 
    mod_gzip_dechunk Yes 
    mod_gzip_item_include file \.(html?|txt|css|js|pl)$ 
    mod_gzip_item_include handler ^cgi-script$ 
    mod_gzip_item_include mime ^text/.* 
    mod_gzip_item_include mime ^application/x-javascript.* 
    mod_gzip_item_exclude mime ^image/.* 
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 
</ifModule> 
<IfModule mod_deflate.c> 
AddOutputFilterByType DEFLATE text/plain 
AddOutputFilterByType DEFLATE text/html 
#AddOutputFilterByType DEFLATE text/xml 
AddOutputFilterByType DEFLATE text/css 
AddOutputFilterByType DEFLATE application/javascript 
AddOutputFilterByType DEFLATE application/x-javascript 
</IfModule> 

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www\.example\.org 
RewriteRule (.*) http://www.example.org/$1 [R=301,L] 
#RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteRule ^sitemap.xml /sitemap.php?p=xml [L] 
RewriteRule ^sitemap.xsl /sitemap.php?p=xsl [L] 
RewriteRule ^sitemap.css /sitemap.php?p=css [L] 
RewriteRule ^sitemap.js /sitemap.php?p=js [L] 
RewriteRule ^robots.txt /sitemap.php?p=txt [L] 
RewriteRule ^gallery - [L] 
RewriteRule ^controller\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

的雙重檢查RewriteCond %{REQUEST_FILENAME} !-f背後的原因是因爲另一個問題我不得不嘗試時只處理文件不存在的特定類型的文件。 (漂亮404沒有找到頁面時,JPG /等缺失)。

正如你所看到的,controller.php完成所有認證等繁重的工作如果我註釋掉任何含^(.*)$ controller.php?行,除非我直接調用控制器我不明白500的錯誤,讓它的基礎上的重定向應用程序根路徑。

這可以在我的Debian 8和Ubuntu 11盒以及Windows 10上完美地工作。管理員基於開源項目otp-thing並且運行良好。當全能wordpress位於網站的根目錄時,只是在處理重定向時遇到了一些麻煩。

似乎沒有任何代碼問題(如果是的話,他們會在Debian 8,Ubuntu 11,尤其是Windows 10的其他測試中出現)。

在此版本的cPanel運行的服務器軟件如下:

Server version: Apache/2.4.18 (Unix) 
Server built: Mar 1 2016 10:43:46 
Cpanel::Easy::Apache v3.32.10 rev9999 
Server's Module Magic Number: 20120211:52 
Server loaded: APR 1.5.2, APR-UTIL 1.5.4 
Compiled using: APR 1.5.2, APR-UTIL 1.5.4 
Architecture: 64-bit 
Server MPM:  prefork 
    threaded:  no 
    forked:  yes (variable process count) 
Server compiled with.... 
-D APR_HAS_SENDFILE 
-D APR_HAS_MMAP 
-D APR_HAVE_IPV6 (IPv4-mapped addresses disabled) 
-D APR_USE_SYSVSEM_SERIALIZE 
-D APR_USE_PTHREAD_SERIALIZE 
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT 
-D APR_HAS_OTHER_CHILD 
-D AP_HAVE_RELIABLE_PIPED_LOGS 
-D DYNAMIC_MODULE_LIMIT=256 
-D HTTPD_ROOT="/usr/local/apache" 
-D SUEXEC_BIN="/usr/local/apache/bin/suexec" 
-D DEFAULT_PIDLOG="logs/httpd.pid" 
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status" 
-D DEFAULT_ERRORLOG="logs/error_log" 
-D AP_TYPES_CONFIG_FILE="conf/mime.types" 
-D SERVER_CONFIG_FILE="conf/httpd.conf" 

和PHP

PHP 5.6.18 (cli) (built: Mar 1 2016 10:47:52) 
Copyright (c) 1997-2016 The PHP Group 
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies 
    with the ionCube PHP Loader v4.7.5, Copyright (c) 2002-2014, by ionCube Ltd., and 
    with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies 

另外,如果你看一下項目源OTP-的事情,你會發現某些嵌套目錄有意阻止公共訪問(app/cache,app/templates_c等)

Apache /usr/local/apache/error_log報告的錯誤是:

[星期四21年8月25日:33:21.323468 2016] [芯:錯誤] [PID 15805] [客戶端XX.XX.XX.XX:XXXXX] AH00124:請求超過了10個內部重定向限制由於可能的配置錯誤。如果需要,使用'LimitInternalRecursion'來增加限制。使用'LogLevel debug'來獲得回溯。如果我註釋掉從gallery/admin/.htaccess文件RewriteRule線的任何組合

的信息是相同的。

我曾嘗試在'controller.php'之前添加路徑,但是這加劇了問題,但總體而言,這裏沒有改變這個問題。

我該怎麼做才能確保所有這些東西都起作用,或者甚至作爲解決方法,我如何通過合併它們將otp-thing的htaccess規則移動到wordpress htaccess文件中(指令如何調整後)。

+1

規則:當你得到一個500,你的第一站是檢查Apache的錯誤日誌的詳細信息。其他任何東西都是毫無意義的 - 除非你知道問題是什麼,否則在黑暗中隨意刺傷沒有意義。 –

+0

@MarcB - 抱歉,我應該發佈該信息。 apache日誌是非特定的,因爲這是cPanel,因此需要調整以獲取更多信息。添加上面的消息 –

+0

@MarcB - 另外,我的第一站是啓用PHP錯誤輸出 - 然後apache日誌,因爲經常有很多錯誤在PHP中顯示爲500錯誤(丟失波形大括號等),如果PHP錯誤報告/顯示設置爲「生產」值 - 特別是在php-fpm/etc環境中。 –

回答

1

這應該在/gallery/admin/.htaccess工作:拇指

RewriteEngine On 
RewrtieBase /gallery/admin/ 

# skip any rule below this for controller.php or for valid files/directories 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_URI} /controller\.php$ [NC] 
RewriteRule^- [L] 

# rewrite all except certain static resource extensions to controller.php 
RewriteCond %{REQUEST_URI} !\.(jpe?g|png|bmp|gif|css|js|map|ttf|woff|woff2|svg|eot)$ 
RewriteRule ^.*$ controller.php?page=$0 [L,QSA] 

# rewrite not found static resource extensions 
RewriteRule ^.*$ controller.php?page=error&rewritten=1&missing=$0 [L,QSA]