2012-03-18 64 views
1

我正在與客戶端合作,我們剛剛將他們的網站從Godaddy(ew!)移至Pair Networks。我個人對客戶使用多年,並與他們有很好的經驗。不幸的是,對於這個問題,因爲它是一個共享託管計劃的URL重寫技術支持不屬於支持計劃。令人沮喪的.htaccess URL重寫問題

無論如何,只要我們將網站移動到根.htaccess中的重寫規則中,就不再有效。 .htaccess包含:

RewriteEngine On 
RewriteRule ^((images|styles|scripts|documents)/*.*)$ $1 [L] 
RewriteRule ^(admin/*)$ index.php/$1 [L] 
RewriteRule ^([a-zA-Z0-9]+)$ page/id/$1 
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico) 
RewriteRule ^(.*)$ index.php/$1 [L] 

根據Apache的錯誤是太多重定向導致顯示錯誤500。如果我註釋掉這個:

#RewriteRule ^(.*)$ index.php/$1 [L] 

則默認的頁面加載(index.php文件設置;如果沒有在URL中指定一個默認的),但隨後沒有其他頁面可以加載。我已經爲每個URL格式手動添加條目到的.htaccess保持網站的功能,從而導致此:

RewriteEngine On 
RewriteRule ^((images|styles|scripts|documents)/*.*)$ $1 [L]  
RewriteRule ^(admin/*)$ index.php/$1 [L] 
RewriteRule ^(admin/([a-zA-Z0-9]+))$ index.php/$1 [L] 
RewriteRule ^(admin/([a-zA-Z0-9]+)/([a-zA-Z0-9]+))$ index.php/$1 [L] 
RewriteRule ^(page/id/*)$ index.php/$1 [L] 
RewriteRule ^(page/submit)$ index.php/page/submit [L] 
RewriteRule ^([a-zA-Z0-9]+)$ index.php/page/id/$1 
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico) 
#RewriteRule ^(.*)$ index.php/$1 [L] 

該網站使用笨,所以預期的最終重寫URL格式爲:http://server/index.php/page/id/example加載http://server/example

我在配對服務器上使用完全相同的CMS和相同的原始.htaccess的另一個客戶端大概6年沒有問題,所以我有點大驚小怪,爲什麼這會突然導致問題。他們甚至使用相同版本的Apache和PHP(分別爲2.2.22和5.3.8)。

有沒有人有什麼問題的想法?我寧願不必手動定義這樣的所有路線。

回答

3

我們已經使用了一組非常類似的規則,多年來沒有任何問題。除了我們在該行之前有兩個RewriteCond規則來檢查請求不是針對文件或目錄:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

哇,這就是它所需要的!不能相信我以前沒有嘗試過,我想我陷入了爲什麼它在一臺服務器上工作而不是新服務器甚至想到這個問題的問題。感謝您的建議! – Kettch19 2012-03-18 08:06:24