【问题标题】:Unable to remove index.php in WAMP with Codeigniter URL无法使用 Codeigniter URL 删除 WAMP 中的 index.php
【发布时间】:2015-09-15 01:22:25
【问题描述】:

我想删除 URL 中的 index.php,但它不起作用。 这是我所做的:

  1. 我在我的 Apache 中启用了 rewrite_module,然后重新启动服务器
  2. 我在我的 codeigniter 文件夹中编辑 .htaccess。我根据文档中的示例添加了这个。

    重写引擎开启

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    重写规则 ^(.*)$ index.php/$1 [L]

  3. 那我也把app/config里面的index.php去掉

  4. 然后我创建一个简单的控制器:

    class Users extends CI_Controller {
    
        public function __construct() {
            parent::__construct();
        }
    
        public function index() {
            echo "hello world";
        }
    
    }
    

当我访问这个网址时:

http://localhost/order_menu/users

我收到了这个错误:

Not Found

The requested URL /order_menu/users was not found on this server.

你能帮我解决这个问题吗?

【问题讨论】:

  • 你在使用 wamp 服务器吗?你有没有在 config/routes.php 中设置一些路由
  • 我正在使用 wamserver。在我的路线中,我有默认的 CodeIgniter
  • 你在 wamp 中启用了 rewrite mod 吗?

标签: php .htaccess codeigniter


【解决方案1】:

删除 wamp apache 服务器上 codeigniter 中的 index.php!

当您使用 wamp 时,请确保您已启用 Apache Modules "rewrite_module" 重启服务器

第二

在项目的主目录中试试这个 htaccess

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

然后转到 application/config/config.php

查找 $config['index_page'] = 'index.php';

然后将 index.php 设为空白

替换为 $config['index_page'] = '';

您可能需要配置您的路线

CI3:http://www.codeigniter.com/user_guide/general/routing.html

CI2:http://www.codeigniter.com/userguide2/general/routing.html

【讨论】:

  • 感谢您的回答。还有一些指导方针.. :)
猜你喜欢
  • 2011-10-28
  • 2014-08-19
  • 2015-10-27
  • 2018-03-02
  • 2013-08-09
  • 2012-12-27
  • 1970-01-01
  • 1970-01-01
  • 2015-05-26
相关资源
最近更新 更多