2014-08-28 71 views
0

我在Ubuntu 12.04.3上運行Apache 2.2.22(Windows 8.1上的Oracle VM)。 使用PHP phpinfo()函數我在加載模塊下的apache2handler部分看到了mod_rewrite,所以啓用了mod_rewrite。刪除CodeIgniter 2.2.0上的index.php

我做了以下修改我的CI配置文件(application /配置/ config.php文件),

$config['index_page'] = 'index.php'; to: $config['index_page'] = ''; 
$config['uri_protocol'] = 'AUTO'; to: $config['uri_protocol'] = 'PATH_INFO'; 

我已經試過無數版本的這個(位於CI的根目錄.htaccess文件):

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

但還沒有得到它的工作。 我還在這裏錯過了什麼?

回答

2

這工作!

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

所以,我們是否必須在根目錄下創建'.htaccess'文件?正如我們知道'.htaccess'文件不存在於codeigniter 2.2的根目錄中 – 2015-03-16 02:22:09

1

假設您的文件夾結構類似於/ var/www/html/testsite,並且您的url是localhost/testsite,那麼上面的重寫規則將在/ var/www/html而不是/ var/www/html/testsite。因此,在/ var/www/html/testsite的等效文件夾中,您可以嘗試在位於/ var/www/html/testsite中的.htaccess文件中使用以下內容:.htaccess文件位於/ var/www/html/www/html等/測試網站/。所以你必須/var/www/html/testsite/.htaccess的代碼...

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L] 

我所做的是刪除了前導/在最後一行的重寫規則,所以它不是標題回到默認的文檔根目錄。

+0

感謝您的回覆蒂姆,但沒有奏效。我的CI是建立在我的虛擬機共享目錄是這樣的: 別名/測試網站/媒體/ sf_testsite/ <目錄「/媒體/ sf_testsite /」> 選項-Indexes多視圖 的AllowOverride無 訂購允許,拒絕 從允許所有 – olen 2014-08-30 14:56:57