ci3如何隐藏index.php?

在根目录里添加一个名为.htaccess的文件,内容为:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<IfModule mod_rewrite.c>

    RewriteEngine on

    Options +FollowSymLinks

    RewriteBase /

     

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php/$1

</IfModule>

<IfModule !mod_rewrite.c>

    ErrorDocument 404 /index.php

</IfModule> 

allow from all

然后修改你的ci框架中 application/config文件夹中的 routes.php

1

2

$route['default_controller'] = "你的控制器名字/方法";

$route['404_override'] = '';

控制器中

<?php
defined('BASEPATH') OR exit('No direct script access allowed');



class Indexx extends CI_Controller {


   public function index()
   {
        $base_url = $this->config->item('base_url');

        $this->load->view('indexx/index',array('base_url'=>$base_url));
   }
}

视图中

<link href="<?php echo $base_url; ?>static/admin/style/bootstrap.css" rel="stylesheet">
<link href="<?php echo $base_url; ?>static/admin/style/font-awesome.css" rel="stylesheet">
<link href="<?php echo $base_url; ?>static/admin/style/weather-icons.css" rel="stylesheet">

<!--Beyond styles-->
<link id="beyond-link" href="<?php echo $base_url; ?>static/admin/style/beyond.css" rel="stylesheet" type="text/css">
<link href="<?php echo $base_url; ?>static/admin/style/demo.css" rel="stylesheet">
<link href="<?php echo $base_url; ?>static/admin/style/typicons.css" rel="stylesheet">
<link href="<?php echo $base_url; ?>static/admin/style/animate.css" rel="stylesheet">

猜你喜欢

转载自blog.csdn.net/qq_40270754/article/details/84028108