2013-12-08 47 views
1

我想從CodeIgniter中的路徑中刪除index.php。我無法從CodeIgniter URL中刪除index.php

我試圖更改配置文件爲以下index_page的價值:

$config['index_page'] = ''; 

然後我嘗試了所有這些的.htaccess:

RewriteEngine on 
RewriteBase/
# Hide the application and system directories by redirecting the request to index.php 
RewriteRule ^(application|system|\.svn) index.php/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [QSA,L] 

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

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

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

<Files "index.php"> 
AcceptPathInfo On 
</Files> 

但他們都沒有工作。

我也試圖給uri_protocol改成這樣:

$config['uri_protocol'] = 'ORIG_PATH_INFO'; 

但它仍然無法正常工作。

我該如何解決這個問題?

編輯:

我想這個代碼,以檢查是否mod_rewrite的啓用:

<?php 
if(! function_exists('apache_get_modules')){ phpinfo(); die; } 
$result = ' not available'; 
if(in_array('mod_rewrite',apache_get_modules())) $result = 'available'; 

?> 
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $result"; ?></p> 

我得到這樣的結果:

的Apache/2.2.22(Ubuntu的)

mod_rewrite不可用

+0

嘗試設置URL協議自動''$配置[ 'uri_protocol'] = '自動','' –

+0

你的htaccess看起來不錯。你確定你的網絡服務器支持htaccess並啓用了mod_rewrite嗎? –

+0

@jonijones我已經這樣做了,但同樣的問題:/ –

回答

3

我有同樣的問題..然後最後將其與下面的代碼工作

只要按照這些簡單的步驟:

1.將以下代碼.htaccss文件..
2.把它在主項目文件夾中(不是應用程序文件夾)
3.將代碼第3行中的「/ projectFolderName /」部分重命名爲 您的項目文件夾名稱。

然後你就完成了。刷新並看看。

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /projectFolderName/ 

RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

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

大拇指! – Ikbel

0

這適用於我。 Inyour .htaccess文件的寫:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L] 

,並在你的config.php文件:

$config['uri_protocol'] = 'AUTO'; 

確保YOUT的htaccess是不是在應用程序文件夾的根文件夾。