2012-02-20 61 views
2

我試圖訪問沒有'index.php'的CodeIgniter網址。下面是我所採取的步驟:從CodeIgniter網址中刪除index.php

  1. 經過mod_rewrite的啓用 - 我設定的規則來重定向所有請求到谷歌,這工作。還檢查了 '設置AllowOverride全部' 設置

  2. 新增.htaccess文件下列要求:

    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L] 
    
  3. 設置在Web服務器上我的目錄結構如下:

    /home/wwwsunde/ 
    -> application 
    -> system 
    -> public_html 
        -> index.php 
        -> .htaccess 
    
  4. 更新我的應用程序/配置文件,使系統和a pplication路徑是「../system」和「../application」

  5. 嘗試從2個網址

    http://109.234.194.207/~wwwsunde/index.php/welcome/membership WORKS 
    http://109.234.194.207/~wwwsunde/welcome/membership DOES NOT WORK 
    
  6. 我還設置CodeIgniter的索引頁變量爲空白按訪問網站

所示的錯誤消息的指南:

The requested URL /home/wwwsunde/public_html/index.php/welcome/membership was not found on this server. 

我ö的想法,可能是錯誤的UT - 這是一個Apache或服務器的問題,但我不知道是什麼......

+0

的index.php是一個目錄,而不是一個文件? – 2012-02-20 21:19:30

+0

您是否嘗試了http://codeigniter.com/wiki/mod_rewrite上的說明? – 2012-02-20 21:21:18

+0

我一直在這裏約一個小時,沒有成功,包括該網站 – codinghands 2012-02-20 21:26:00

回答

3

哦......我知道爲什麼......使這個你重寫規則:

RewriteRule .* index.php/$0 [PT] 

[L]你只是一個'最後的規則',但不會做你想要安靜地處理背景殼遊戲的退出重寫。這將是一個無止境的循環。如果這不起作用,請在重寫中指定完整網址,例如:

RewriteRule .* http://109.234.194.207/~wwwsunde/index.php/$0 [PT] 
+0

404路徑改爲:'/ home/wwwsunde/public_html /〜wwwsunde/index.php/welcome/membership' – codinghands 2012-02-20 21:25:23

+0

@codinghands啊,確認你的文檔根目錄是public_html,你的服務器名稱是109.234.194.207/~wwwsunde/就像如果你在mac上使用共享桌面apache – Ray 2012-02-20 21:41:30

+0

是的,文檔根目錄是public_html,服務器是'http://109.234.194.207/~wwwsunde/'(在config base_url中)。服務器是安裝了WHM/cPanel的VPS。 – codinghands 2012-02-20 21:43:33

1

您從哪裏得知索引頁應該是空白的?你的意思是index.php?它應該是這樣的:

<?php 
/* 
|--------------------------------------------------------------- 
| PHP ERROR REPORTING LEVEL 
|--------------------------------------------------------------- 
| 
| By default CI runs with error reporting set to ALL. For security 
| reasons you are encouraged to change this when your site goes live. 
| For more info visit: http://www.php.net/error_reporting 
| 
*/ 
     error_reporting(0); 
//  ini_set("display_errors", "on"); 

/* 
|--------------------------------------------------------------- 
| SYSTEM FOLDER NAME 
|--------------------------------------------------------------- 
| 
| This variable must contain the name of your "system" folder. 
| Include the path if the folder is not in the same directory 
| as this file. 
| 
| NO TRAILING SLASH! 
| 
*/ 
     $system_folder = "system"; 

/* 
|--------------------------------------------------------------- 
| APPLICATION FOLDER NAME 
|--------------------------------------------------------------- 
| 
| If you want this front controller to use a different "application" 
| folder then the default one you can set its name here. The folder 
| can also be renamed or relocated anywhere on your server. 
| For more info please see the user guide: 
| http://codeigniter.com/user_guide/general/managing_apps.html 
| 
| 
| NO TRAILING SLASH! 
| 
*/ 
     $application_folder = "application"; 

/* 
|=============================================================== 
| END OF USER CONFIGURABLE SETTINGS 
|=============================================================== 
*/ 


/* 
|--------------------------------------------------------------- 
| SET THE SERVER PATH 
|--------------------------------------------------------------- 
| 
| Let's attempt to determine the full-server path to the "system" 
| folder in order to reduce the possibility of path problems. 
| Note: We only attempt this if the user hasn't specified a 
| full server path. 
| 
*/ 
if (strpos($system_folder, '/') === FALSE) 
{ 
     if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE) 
     { 
       $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder; 
     } 
} 
else 
{ 
     // Swap directory separators to Unix style for consistency 
     $system_folder = str_replace("\\", "/", $system_folder); 
} 

/* 
|--------------------------------------------------------------- 
| DEFINE APPLICATION CONSTANTS 
|--------------------------------------------------------------- 
| 
| EXT   - The file extension. Typically ".php" 
| FCPATH  - The full server path to THIS file 
| SELF   - The name of THIS file (typically "index.php") 
| BASEPATH  - The full server path to the "system" folder 
| APPPATH  - The full server path to the "application" folder 
| MEDIAPATH - The full server path to the "media" folder 
*/ 
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION)); 
define('FCPATH', __FILE__); 
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); 
define('BASEPATH', $system_folder.'/'); 
define('MEDIAPATH', dirname(__FILE__).'/media'); 

if (is_dir($application_folder)) 
{ 
     define('APPPATH', $application_folder.'/'); 
} 
else 
{ 
     if ($application_folder == '') 
     { 
       $application_folder = 'application'; 
     } 

     define('APPPATH', BASEPATH.$application_folder.'/'); 
} 

/* 
|--------------------------------------------------------------- 
| LOAD THE FRONT CONTROLLER 
|--------------------------------------------------------------- 
| 
| And away we go... 
| 
*/ 
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; 

/* End of file index.php */ 
/* Location: ./index.php */ 

提醒你,我隨機抓起這個從我們的CI項目之一,所以它可能是定製的 - 我真的不記得 - 但它絕對不是空白。

此外,配置:

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

和htaccess的:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    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

我應該說'indexpage'變量,而不是實際的index.php我已經設置了我的系統和應用程序文件夾路徑 – codinghands 2012-02-20 21:54:21

+0

夠公平 - 我的帖子可能完全沒有用,然後對不起 – 2012-02-20 22:03:25

+0

沒有道歉要求: )感謝您的期待。 – codinghands 2012-02-20 22:05:11