去掉php框架CI默认url中的index.php

CI默认的rewrite url中是类似这样的

例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样 http://localhost/CodeIgniter/index.php/welcome。

不太好看,怎么把其中的index.php取掉呢?

解决方法如下:

第一步:

Apache Url Rewrite 配置(php伪静态)

检查 Apache 中 conf/httpd.conf 中是否存在如下一段代码:

#LoadModule rewrite_module modules/mod_rewrite.so

把 LoadModule前边的#去掉。

第二步:

在网站根目录添加.htaccess(和application、system在一个目录下)

内容为:

RewriteEngine on   

RewriteCond $1 !^(index\.php|images|robots\.txt)   

RewriteRule ^(.*)$ /index.php/$1 [L]

备注:

1、要注意 /index.php/$1 要根据你目录(Web 目录,比如 http://www.domain.com/index.php)的实际情况来定。

比如网站根目录是 /ci/index.php 则要写成 /ci/index.php/$1

2、RewriteCond $1 !^(index\.php|images|robots\.txt)

上面的代码意思是排除某些目录或文件,使得这些目录不会 rewrite 到 index.php 上,这一般用在图片、js、css 等外部资源上。也就是说非 PHP 代码都要排除出去。(这里我排除了 images 目录和 robots.txt 文件,当然 index.php 也应该被排除)

第三步:

修改application/config.php

查找$config[‘index_page‘] = "index.php";

修改为:$config[‘index_page‘] = "";

第四步:

httpd.conf文件中:

AllowOverride None

改为

AllowOverride All

注意:如果你做了虚拟站点,在httpd-vhosts.conf中做了多站点配置,就像我这样:

<VirtualHost *:81>
 DocumentRoot "d:/wamp/www/nxtv"
 ServerName 81
 <Directory "d:/wamp/www/nxtv">
  Options FollowSymLinks
  AllowOverride All
  Require all granted
 </Directory>
</VirtualHost>

<VirtualHost *:82>
 DocumentRoot "d:/wamp/www/codeigniter220"
 ServerName localhost:82
 <Directory "d:/wamp/www/codeigniter220">
  Options FollowSymLinks
  AllowOverride All
  Require all granted
 </Directory>

要记得 把 AllowOverride None 改为  AllowOverride All,我就在这里吃亏了=。=

时间: 2024-08-10 23:27:38

去掉php框架CI默认url中的index.php的相关文章

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

去掉CodeIgniter(CI)默认url中的index.php的步骤: 1.打开apache的配置文件,conf/httpd.conf : 1 LoadModule rewrite_module modules/mod_rewrite.so 把该行前的#去掉. 搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为: 1 AllowOverride All 2.在CI的根目录下,即在index.php,system的同级目录下,建立

CI框架 .htaccess 隐藏url中index.php的解决

CodeIgniter(以下简称"CI")是一款国外优秀的PHP轻量级MVC框架,它支持PHP4和PHP5,是开发中小型可拓展性需求高的Web应用程序的利器.目前你所见到的这个博客程序,正是采用CI进行的编写. 秉承MVC架构的思想,CI中的所有控制器都需要经过单点入口文件index.php(默认)来加载调用.也就是说,在默认情况下,所有CI开发项目的URL都形如以下这种形式: http://localhost/index.php/blog/logs/this_is_a_test_en

PHP CI(CodeIgniter) 如何去掉url中的index.php

1.打开Apache配置文件httpd.conf,找到 1 #LoadModule rewrite_module modules/mod_rewrite.so 去掉前面的# 搜索AllowOverride,将相应Directory下的AllowOverride设置为All 1 AllowOverride All 2.在CI的根目录下,建立.htaccess文件,文件内容如下 1 RewriteEngine On 2 3 RewriteCond %{REQUEST_URI} ^system.* 4

nginx去掉url中的index.php

使用情境:我想输入www.abc.com/a/1后,跳转到www.abc.com/index.php/a/1 配置Nginx.conf在你的虚拟主机下添加:  location / {      if (!-e $request_filename){           rewrite ^/(.*)$ /index.php/$1 last;      } } 如果你的项目入口文件在一个子目录内,则: location /目录/ {      if (!-e $request_filename){

ThinkPHP 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php

去掉 URL 中的 index.php ThinkPHP 作为 PHP 框架,是单一入口的,那么其原始的 URL 便不是那么友好.但 ThinkPHP 提供了各种机制来定制需要的 URL 格式,配合 Apache .htaccess 文件,更是可以定制出人性化的更利于 SEO 的 URL 地址来. .htaccess文件是 Apache 服务器中的一个配置文件,它负责相关目录下的网页配置.我们可以利用 .htaccess 文件的 Rewrite 规则来隐藏掉 ThinkPHP URL 中的 in

[中级] 有效删除URL中的index.php

如果你刚接触CI不久又或者刚刚研读CI的使用手册的话,关于如何有效删除URL中index.php以使URL看起来更友好美观的问题,可能是你面对的第一个较为复杂的问题!本贴不是原创,而是一个各种意见的综合!但本帖提出的解决方案可以有效解决Apache和IIS两种环境下的配置问题,同时也可以有效,避免部分虚拟LINUX虚拟主机上可能出现的no input file specified错误!如果你还在为index.php的问题而苦苦寻觅解决方案,或许这里会是你的最后一站! 官方解决方案 默认情况下,i

Joomla的Url中去除index.php

最近在研究Joomla系统(一个著名的CMS系统),安装之后发现页面的URL中始终有一个index.php存在,感觉非常碍眼,决心将其除之而后快,废话少说,下面以2.5版本为例奉上去除步骤. 1. 登录管理后台,在"Site"->"Global Configuration"->"Site"中的"SEO Settings"中全部勾选"Yes": 2. 创建.htaccess文件:将Joomla安装

ThinkPHP 隐藏URL中的 index.php

去掉 URL 中的 index.php 通常的URL里面含有index.php,为了达到更好的SEO效果可能需要去掉URL里面的index.php ,通过URL重写的方式可以达到这种效果,通常需要服务器开启URL_REWRITE模块才能支持. 例如原来的 URL 为: http://127.0.0.1/index.php/Index/insert 去掉 index.php 之后变为: http://127.0.0.1/Index/insert 第一步:更改Apache的httpd.conf 配置

[tp3.2.1]开启URL(重写模式),省略URL中的index.php

重写模式(省略url中的index.php) 在apache配置文件httpd.conf中,查找 1.mod_rewrite.so, 启动此模块 2.AllowOverride , 值= All 3. 把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下 1 <IfModule mod_rewrite.c>2     Options +FollowSymlinks3     RewriteEngine on4 5     RewriteCond %{REQUEST_FILENA