在CodeIgniter 3中删除index.php的问题

问题描述:

我想访问CodeIgniter中没有 index.php 的URL。这是我的 Blog 控制器

I want to access my URL's without index.php in CodeIgniter. Here is my Blog controller

class Blog extends CI_Controller {

    public function index() {
        echo 'hello world';
    }

    public function about() {
        echo 'about page';
    }
}

现在我可以访问索引通过 http://localhost/codeigniter/index.php/Blog ,但我需要使用此URL 进行访问http:// localhost / codeigniter / Blog

Now I can access index via http://localhost/codeigniter/index.php/Blog, but I need to access it with this URL http://localhost/codeigniter/Blog.

注意

我从配置文件
.htaccess 文件

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

Environment

Windows,XAMPP,PHP版本5.6.3

Windows, XAMPP, PHP Version 5.6.3

如何从URL中删除index.php的问题已经问了很多次,这与 codeigniter 2的含义相同和3

How to removed index.php from url has been asked so many times, It is the same as what is for codeigniter 2 and 3.

用于带有Codeigniter Windows的Xampp

For Xampp With Codeigniter Windows

查找application / config / config.php

Find application/config/config.php

替换此

$ config ['base_url'] =;

使用此

$ config ['base_url'] =您的项目的网址;

替换为

$ config ['index_page'] = index.php

使用此

$ config ['index_page'] =

在主目录中创建名为.htaccess的文件

In main directory create file called .htaccess

我在xampp中使用以下代码对我来说效果很好视窗。更多htacces 此处

I use code below works fine for me in xampp in windows. More htacces here

Options +FollowSymLinks
Options -Indexes

<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
    Order deny,allow
    Deny from all
</FilesMatch>

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]

注意:请确保您的控制器类似于示例Welcome.php而不是welcome.php,并且您可能还需要在路由中创建新路由.php如果删除index.php

Note: make sure your controllers are like example Welcome.php instead of welcome.php also you might need to create new routes in your route.php if remove index.php