2011-12-19 256 views
1

我有.htaccess文件,其中包括以下代碼。.htaccess無法正常工作

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?q=$1 [L] 
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA] 

我想.htaccess文件滿足以下要求。 if 1)url/admin然後轉到admin文件夾並選擇它的.htaccess文件 2)url/imagefactory然後進入imagefactory文件夾並選擇它的文件名爲index.php 3)url /然後選擇根目錄index.php文件

+0

你有完全控制權?如果是,請不要使用.htaccess,而應使用虛擬主機和「」聲明。 – fge 2011-12-19 08:55:59

+0

只是如果用戶轉到url /那麼它將默認索引。[PHP的,HTML等],如果你使用Apache(即時通訊不知道其他網絡服務器)。 至於其他的,你可能必須做一個重定向,因爲你在那裏做什麼意味着這兩個將是有效的iirc;所以我的意思是:url/admin和url/this/is/my/admin /文件夾都是有效的。 – DarkMantis 2011-12-19 08:56:38

回答

1

嘗試在Apache服務器這

RewriteEngine on 
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA] 
RewriteRule ^admin/.$ - [PT] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?q=$1 
+0

Thanx很多Shoogle..This代碼工作正常.. – meghshah 2011-12-19 09:54:26

0

您應該放置最後一個規則1的位置。此規則RewriteRule ^(.*)$ index.php?q=$1 [L]將匹配任何內容,並且這裏的[L]屬性表示不匹配其他規則時將進行評估。如果你像下面這樣重新排列,它應該可以工作。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA] 
RewriteRule ^(.*)$ index.php?q=$1 
0

按順序讀取.htaccess文件。 RewriteCond僅適用於一個規則。

因此,所有你需要的是:

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA, L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^/admin/(.*)$ 
RewriteRule ^(.*)$ index.php?q=$1 [QSA, L] 

第二塊是包羅萬象的,這樣,如果它不是從目錄管理,使用默認的根index.php文件。

+0

它給出了這樣的錯誤:內部服務器錯誤 – meghshah 2011-12-19 09:32:04