2017-10-18 76 views
-1

我需要從我的codeigniter網址中移除index.php。這是我在.htaccess文件代碼:無法從活動網站中的codeigniter網址中移除index.php

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.php文件修改:

$config['base_url'] = 'http://example.com/' 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

在我的本地工作的罰款。但在我的生活網站,它會產生一個404錯誤。

我可以通過index.php('http://example.com/index.php/Home')加載url,但'http://example.com/Home'生成404錯誤。爲什麼這隻發生在現場?還有其他需要改變嗎? 一兩件事,它不是一個Apache服務器,我的網站發表在IIS

+0

嘗試從第二行 – shashi

+0

刪除[R = 302,L]僅適用於現場?如果我從我的代碼中刪除它將重定向到我的儀表板在本地主機 – geeth

+0

該網站發佈在IIS – geeth

回答

0

粘貼.htaccess文件

RewriteEngine On 
    #RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule (.*) index.php/$1 

下面的代碼,然後轉到您的配置文件中的配置文件夾,刪除索引。從

$config['index_page'] = ''; 

PHP的,如果你的網站是在子文件夾中,那麼你必須後添加子文件夾名稱「#RewriteBase /」

+0

它不在子文件夾中。那麼我需要包含RewriteBase? – geeth

+0

是的,你確實需要添加 – interntseekho

0

我認爲你是英里ssing

RewriteBase/

0

以下是完整的htaccess的應駐留在主項目文件夾。如果它位於子文件夾中,則必須編寫rewritebase。

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading 
    # slashes. 
    # If your page resides at 
    # http://www.example.com/mypage/test1 
    # then use 
    # RewriteBase /mypage/test1/ 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 
+0

請試試看,讓我知道它的工作與否 –