2012-02-20 137 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