2016-01-15 55 views
0

我想刪除index.php直接訪問我的控制器。但是,我不能直接去我的控制器。我必須使用index.php。例如:我想去的 http://example.com/my_controller/method代替http://example.com/index.php/my_controller/method無法刪除Codeigniter中的index.php

順便說一句,我用我的測試服務器,而不是本地服務器像XAMPP。我在我的服務器上啓用了apache mod重寫。

我嘗試了很多htaccess規則,但我無法工作。請幫幫我!

這是我的.htaccess文件:

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

我的config.php:

$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

如何我可以直接去?

+4

的[笨去除URL的index.php(可能的複製http://stackoverflow.com/questions/19183311驗證碼/ codeigniter-removing-index-php-from-url) –

+0

首先使用什麼版本的codeigniter以及localhost xampp,wamp等 – user4419336

+0

不,我試過了。 –

回答

1

如何驗證mod_rewrite是否被實際啓用。你可以按照下列指示:How to check whether mod_rewrite is enable on server?

+0

是的,我檢查,它啓用。圖像鏈接是http://pasteboard.co/P513xT9.png –

+0

如何刪除If語句... < IfModule mod_rewrite.c> – plhyhc

+0

我試過了,但是沒有成功::( –

0

嘗試在你的.htaccess文件

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|css|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

我試過了,但沒有成功:( –

+0

在更改.htaccess之後重新啓動了服務器 – sasy

+0

是的,我做過了,如果我沒有重新啓動它,通過使用phpinfo()在加載的模塊中看不到模塊 –