2013-11-24 82 views
5

我有一個爲codeigniter 2.1.4中的客戶端開發的小項目,他現在堅持遷移到codeigniter 3 DEV版本。我知道這不是一個好的理念,但... 我的問題是,我無法從url中刪除index.php。Codeigniter 3刪除index.php問題

這是我的.htaccess文件:

Options +FollowSymLinks 
    RewriteEngine on 

    # Send request via index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

我從config.php文件刪除的index.php
沒有運氣
我重新安裝了LAMP服務器(我是在Ubuntu 12.04' ),重新配置
我在Codeigniter 2.1.4和Laravel 4上開發的本地服務器上有其他項目,它們工作得很好,但是這個項目讓我很難過。
謝謝!

+0

只是出於好奇:你的客戶如何區分版本2和3,但不能轉換自己? –

+0

@php_nub_qq ya,無論如何,我正在讀CI3的全部內容:@ –

+1

他不得不在某個人的腦袋裏推這個東西。 – Chiribuc

回答

2

如果您的Apache服務器啓用了mod_rewrite,您可以通過使用帶有一些簡單規則的.htaccess文件輕鬆刪除此文件。

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

取出?的index.php

-1

後,我再次克隆Git倉庫,並提出了全新安裝的燈,現在它的工作原理。

6

請下面的代碼直接添加到的.htaccess文件並將其包含到您/codeigniter_project_folder/.htacess

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

你的CI項目的根目錄中創建新的.htaccess文件,並添加代碼那裏。不要更改應用程序文件夾中的.htaccess文件。這是爲我工作

0

剛剛從根下載CI版本2.2.0

複製.htaccesshtaccess.txt並粘貼在你的笨3項目。

不要忘記從.htaccess文件更改項目名稱。

11

我做了這樣:

創造了的.htaccess與內容項目的根文件夾:

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

然後,在config.php中我修改了這一行。

來源:

$config['url_suffix'] = 'index.php'; 

要:

$config['url_suffix'] = ''; 
0
  1. 創建您的www/project_folder一個新的htaccess的文件或您的htdocs/project_folder

  2. 確保mod_rewrite的是使用我的使用echo phpinfo()

  3. 只需粘貼下面的代碼,它應該工作:

    <IfModule mod_rewrite.c> 
    
        RewriteEngine on 
        RewriteCond $1 !^(index\.php|images|robots\.txt) 
        RewriteRule ^(.*)$ /project_folder/index.php/$1 [L] 
    </IfModule> 
    
    <IfModule !mod_rewrite.c> 
        ErrorDocument 404 /index.php 
    </IfModule> 
    
  4. 改變項目文件夾到自己的

2

添加以下行的.htaccess文件

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

還編輯application/config/config.php文件。與

$config[‘index_page’] = 「」; 
$config[‘uri_protocol’] = 「AUTO「; 

它會工作。

1
  1. 做一個.htacess文件在你的項目的根文件夾/Your_codeigniter_project_folder/.htacess並粘貼此代碼

    RewriteEngine敘述在

    的RewriteCond%{} REQUEST_FILENAME -f

    的RewriteCond%{} REQUEST_FILENAME! - d

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

  2. 設置的基準URL在config.php文件$config['base_url'] = 'http://yourhost/CI_project_folder/';

  3. 組URL後綴$config['url_suffix'] = '.php';

*如果不起作用請檢查此*

  • 請確保在根文件夾中.htacess停留在那裏沒有任何文件的名稱與您的控制器名稱相同。 例子:你有一個users.php控制器還你有/Your_codeigniter_project_folder/users.php 一個文件,如果有,請刪除它/Your_codeigniter_project_folder/users.php

  • 確保你的服務器上(從該行開始刪除#)

    的LoadModule rewrite_module改寫模式模塊/ mod_rewrite的。所以