且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重写Codeigniter URL以删除index.php

更新时间:2023-02-24 11:31:11

好的,您提到了很多与您的问题相关的Stack链接.

OK, You mentioned lot of Stack links which related to your question.

更改此设置

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

并将其添加到.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

注意:在localhost index.php中的某些时间不会删除.

Note: Some time in localhost index.php will not removed.

包括您的css/js/images

CSS:<link rel="stylesheet" href="<?php echo base_url()?>assets/styles/material-design-icons.css" type="text/css" />
JS:<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/in/easing.js"></script>
图:<img src="<?php echo base_url()?>assets/image/logo.jpg" alt=""/>

CSS:<link rel="stylesheet" href="<?php echo base_url()?>assets/styles/material-design-icons.css" type="text/css" />
JS : <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/in/easing.js"></script>
Img: <img src="<?php echo base_url()?>assets/image/logo.jpg" alt=""/>

文件结构应该是

- application
- assets
  - style
     - material-design-icons.css
     - font.css
     - app.css
  - js
     - easing.js
  - image
     - logo.jpg
- index.php
- .htaccess(Post in my code)

编辑01

config/routes.php

$route['default_controller'] = "";//give default controller name
$route['404_override'] = '';