简体   繁体   English

从CodeIgniter URL中删除index.php

[英]Remove index.php from CodeIgniter URLs

I'm trying to access CodeIgniter URLs without 'index.php'. 我正在尝试不使用'index.php'访问CodeIgniter URL。 Here's the steps I've taken: 这是我已采取的步骤:

  1. Checked mod_rewrite is enabled - I set a rule to redirect all requests to google, which worked. 选中的mod_rewrite已启用 -我设置了一条规则以将所有请求重定向到google,这有效。 Also checked that 'AllowOverride All' was set 还检查了是否设置了“ AllowOverride All”

  2. Added an .htaccess file with the following: 添加了.htaccess文件 ,内容如下:

     RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] 
  3. Set my directory structure on the webserver as follows: 在网络服务器上设置我的目录结构 ,如下所示:

     /home/wwwsunde/ -> application -> system -> public_html -> index.php -> .htaccess 
  4. Updated my application/config files so that the system and application paths are '../system' and '../application' 更新了我的应用程序/配置文件,以便系统和应用程序路径为“ ../system”和“ ../application”

  5. Try to access the site from 2 URLs 尝试从2个URL访问该网站

     http://109.234.194.207/~wwwsunde/index.php/welcome/membership WORKS http://109.234.194.207/~wwwsunde/welcome/membership DOES NOT WORK 
  6. I've also set CodeIgniter's index page variable to blank as per the guide 我还按照指南将CodeIgniter的索引页变量设置为空白

The error message shown: 显示的错误消息:

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

I'm out of ideas as to what could be wrong - it's an Apache or server issue but I'm not sure what... 我对可能出什么问题没有主意-这是Apache或服务器问题,但我不确定是什么...

Oh... I know why... make this your rewrite rule: 哦...我知道为什么...将此设为您的重写规则:

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

The [L] you had was just a 'last rule' but wouldn't do the quit rewrite you want to quietly handle the background shell game. 您拥有的[L]只是“最后一条规则”,但您不想安静地处理背景Shell游戏,因此不会执行退出重写。 It would be an endless loop. 这将是一个无休止的循环。 If this doesn't work, specify the full URL in the rewrite like: 如果这不起作用,请在重写中指定完整的URL,例如:

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

Where did you get that the index page should be blank? 您从哪里得到索引页应该为空白? Do you mean index.php? 你是说index.php吗? It should be something like this: 应该是这样的:

<?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 */

Mind you I randomly grabbed this from one of our CI projects so it might be customized - I don't really remember - but it is definitely not blank. 请注意,我是从我们的一个CI项目中随机获取的,因此可以对其进行自定义-我真的不记得了-但它绝对不是空白。

Also, the config: 另外,配置:

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

and htaccess: 和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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM