How to remove ci's index.php

藏色散人
Release: 2023-03-07 06:16:02
Original
2218 people have browsed it

去掉ci的index.php的方法:首先打开apache的配置文件;然后将相关htaccess的相关信息改为“AllowOverride All”;接着在CI的根目录下,建立htaccess;最后重启apache即可。

How to remove ci's index.php

推荐:《PHP视频教程

去掉CodeIgniter(CI)默认url中的index.php的步骤:

1.打开apache的配置文件,conf/httpd.conf :

LoadModule rewrite_module modules/mod_rewrite.so
Copy after login
Copy after login

把该行前的#去掉。

搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为:

AllowOverride All
Copy after login

2.在CI的根目录下,即在index.php,system的同级目录下,建立.htaccess,直接建立该文件名的不会成功,可以先建立记事本文件,另存为该名的文件即可。内容如下(CI手册上也有介绍):

RewriteEngine  on 
 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
 
RewriteRule ^(.*)$ /index.php/$1 [L]
Copy after login

如果文件不是在www的根目录下,例如我的是:

http: //localhost/ci_demo_1/index.php/

第三行需要改写为

RewriteRule ^(.*)$ /CI/index.php/$1 [L]
Copy after login

另外,我的index.php的同级目录下还有assets文件夹,这些需要过滤除去,第二行需要改写为:

RewriteCond $1 !^(index\.php|images|assets|robots\.txt
Copy after login

3.将CI中配置文件(application/config/config.php)中

$config[ 'index_page' ] =  "index.php" ;
Copy after login

改成

$config[ 'index_page' ] =  "" ;
Copy after login

重启apache,完成。

=========================================================================================================================

php 框架ci去index.php的方法

网上有很多方法都要引入.htaccess文件,如果是在测试环境下,动态和静态的文件放到一块,可能测试会有一定的问题(由于全部定向到index.php),静态网页访问不了。

这里提供一种方法,只需要修改http.conf文件,

步骤:

1 :在配置虚拟目录下加入


      Options Indexes FollowSymLinks
      AllowOverride all
      Order allow,deny
      Allow  from  all
    
    
     RewriteEngine  on
     RewriteRule ^/script/(.*) /script/$1 [L]
     RewriteRule ^(.*)$ /index.php?/$1 [L]
    
Copy after login

2 将下面这行前面的;去掉

LoadModule rewrite_module modules/mod_rewrite.so
Copy after login
Copy after login

3 重启apache就可以了,无需加入.htaccess文件

The above is the detailed content of How to remove ci's index.php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!