2012-12-01 96 views
2

htaccess我已經沒有運行,爲什麼?codeigniter htaccess未加載?

有我的htaccess

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteRule ^(.*)$ index.php?/$1 [QSA,L] 
RewriteRule ^(.*)$ index.php?/$1 [QSA,L] 
php_value memory_limit "64M" 
</IfModule> 

和索引頁配置

$config['index_page'] = ''; 

但仍有404頁找不到

http://hostname/blog <=== 404 page not found 
http://hostname/index.php/blog <=== normal page show up 
+1

在重寫規則行前面有一個「#」註釋標記。爲什麼? –

+0

刪除#或試試RewriteRule ^(。*)$ index.php?$ 1 [L] – alditis

+0

得到那個正斜槓^ index.php?/ $ 1 = index.php?$ 1 –

回答

1
RewriteRule ^(.*)$ index.php?/$1 [QSA,L] 

應該是:

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

請參閱http://ellislab.com/codeigniter/user-guide/general/urls.html以及標題爲'Removing the index.php file'的部分您需要使用相同的RewriteRule,但您所使用的RewriteCond並不錯。

+0

RewriteEngine敘述在 的RewriteCond%{REQUEST_FILENAME}!-d 的RewriteCond%{REQUEST_FILENAME}!-f 重寫規則^(。*)$ /的index.php/$ 1 [L] php_value memory_limit的「64M」 我已經 – h454n

+0

刪除IfModule標籤只是爲了確保即使是在服務器啓用了mod_rewrite。只是放在安全的一邊,放一些隨機垃圾文本,如文件中的dghdkhgksdhkg並保存。如果它沒有500服務器錯誤的錯誤,那麼你的htaccess文件甚至沒有被讀取。 –

+0

也改變了我的htaccess仍然沒有找到404頁:( –

0

在應用程序根目錄中包含the.htaccess文件以及index.php文件。 (檢查htaccess的擴展名是正確的,BZ htaccess.txt並沒有爲我工作。)

,並添加以下規則.htaccess文件,

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

然後找到你的應用程序下面的行/ config/config.php文件

$config['index_page'] = 'index.php'; 

將變量設置爲空,如下所示。

$config['index_page'] = ''; 

就是這樣,它爲我工作。

如果沒有進一步的工作,嘗試用這些參數( 'AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI' 和 'ORIG_PATH_INFO')逐一

$config['uri_protocol'] = 'AUTO'; 
0
替換以下變量
RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

這是用Codeigniter's user guide編寫的標準內容,用於刪除index.php文件,您可以在其中添加其他規則。

+0

我已經使用這種方法,但仍然無法工作 – h454n