解析如何去掉CodeIgniter URL中的index.php
2018-10-12 13:53
633 查看
CI默认的rewrite url中是类似这样的,例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样http://localhost/CodeIgniter/index.php/welcome。不太好看,怎么把其中的index.php取掉呢?
1. 打开apache的配置文件,conf/httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so,把该行前的#去掉。
搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为AllowOverride All。
2. 在CI的根目录下,即在index.php,system的同级目录下,建立.htaccess,直接建立该文件名的不会成功,可以先建立记事本文件,另存为该名的文件即可。内容如下(CI手册上也有介绍):
如果文件不是在www的根目录下,例如我的是:http://www.nowamagic.net/CodeIgniter/,第三行需要改写为RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]。
另外,我的index.php的同级目录下还有js文件夹和css文件夹,这些需要过滤除去,第二行需要改写为:RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
3.将CI中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";将$config['index_page'] = ""; 。
重启apache
1. 打开apache的配置文件,conf/httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so,把该行前的#去掉。
搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为AllowOverride All。
2. 在CI的根目录下,即在index.php,system的同级目录下,建立.htaccess,直接建立该文件名的不会成功,可以先建立记事本文件,另存为该名的文件即可。内容如下(CI手册上也有介绍):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
如果文件不是在www的根目录下,例如我的是:http://www.nowamagic.net/CodeIgniter/,第三行需要改写为RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]。
另外,我的index.php的同级目录下还有js文件夹和css文件夹,这些需要过滤除去,第二行需要改写为:RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
3.将CI中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";将$config['index_page'] = ""; 。
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
*/
$config['index_page'] = '';
重启apache
您可能感兴趣的文章:
相关文章推荐
- 解析如何去掉CodeIgniter URL中的index.php
- 解析如何去掉CodeIgniter URL中的index.php
- 如何去掉CodeIgniter URL中的index.php
- 如何去掉CodeIgniter中URL里的index.php
- PHP CI(CodeIgniter) 如何去掉url中的index.php
- 如何去掉CodeIgniter URL中的index.php
- 如何去掉CI (codeigniter)url中的index.php
- 如何去掉Magento默认URL中的index.php
- 去掉CodeIgniter(CI)默认url中的index.php的步骤:
- CodeIgniter框架去掉url中的index.php
- 如何去掉Magento默认URL中的index.php
- CodeIgniter如何去掉Index.php-apache服务器
- 如何去掉Magento默认URL中的index.php
- ThinkPHP如何URL如何去掉index.php(重写模式)
- CodeIgniter 去掉/去除/删除 URL中index.php 的方法
- 如何去掉Magento默认URL中的index.php
- CodeIgniter框架去掉url中的index.php
- 如何去掉Magento默认URL中的index.php
- 如何去掉Magento默认URL中的index.php
- 去掉CodeIgniter(CI)默认url中的index.php