2013-11-28 102 views
1

正如我的標題所說,我從URL中成功刪除index.php,但顯然當我輸入「index.php?」時,它不起作用。我搜索了一切,但沒有發現這個問題。刪除index.php正在工作,但不是爲index.php?

下面是代碼在我.htaccess(我用CI也):

RewriteEngine On 
RewriteBase/

RewriteRule ^index.php/(.*)$ $1 [R=301,L] 
RewriteCond $1 !^(index\.php|resources|robots\.txt)  

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

預先感謝您!

+0

我得到anubhava答案: 的RewriteCond%{THE_REQUEST} /指數\。 php [NC] RewriteRule ^(。*?)index \ .php $%{QUERY_STRING}? [L,R = 302,NC,NE] –

回答

1

上的其他規則頂部添加此規則,以刪除的index.php:

# remove index.php 
RewriteCond %{THE_REQUEST} /index\.php [NC] 
RewriteRule ^(.*?)index\.php$ $1%{QUERY_STRING}? [L,R=302,NC,NE] 
+0

Hi anubhava,來自:www.domain.com/index.php?/testing,現在它重定向到:www.domain.com/?/testing –

+0

是的,這是正確的行爲。 – anubhava

+0

但我想它只是:www.domain.com/testing沒有「?」 –

0

你可以把你的應用程序文件夾出的系統文件夾,並使用此代碼:

RewriteEngine On 

RewriteRule ^index.php/(.*)$ /$1 [R=302,L] 

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

它應該工作。

而且從config/config.php文件使enable_query_stringsFALSE

$config['enable_query_strings'] = FALSE; 

關注這個可以幫助你http://ellislab.com/codeigniter/user-guide/general/urls.html

+0

已經這樣做了之前沒有工作 –

+0

仍然沒有工作,我已經採取了應用程序文件夾從系統文件夾之前 –

+0

更新的支票,一個現在 –

0
RewriteEngine On 

RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 

RewriteCond %{REQUEST_FILENAME} !-d 

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