---
title: "PHP框架queryphp教程：入门九 如何去掉index.php"
author: "web001"
date: "2012-12-14T10:09:23Z"
tags: []
categories: ["编程语言"]
slug: "php-queryphp-index-php"
draft: false
lastmod: "2012-12-14T10:09:23Z"
id: 1747559
url: "https://web001.iteye.com/blog/1747559"
---

**去除index.php测试**

C:\\WINDOWS\\system32\\drivers\\etc\\hosts文件添加一行

内容如下

127.0.0.1 localhost

192.168.0.10 www.tjwzjs.cn

192.168.0.10的是你自己apache使用的IP,就是下面&lt;VirtualHost \*:80&gt;

\*号中的IP，反证能访问你的本地网卡就可以了

http://www.tjwzjs.cn/queryphp/project/index.php/default/index

配置后希望可以变成这样子

http://www.tjwzjs.cn/queryphp/project/default/index.html

记得在inc.ini.php文件里面加多一行

$config\['html']='.html'; 或把前面那个//去掉，这样就可以了

虚拟主机配置测试，AllowOverride FileInfo 将会使用.htaccess配置

**虚拟主机配置测试文件在apache虚拟主机里面:**

&lt;VirtualHost \*:80&gt;

&lt;Directory "D:/work"&gt;

Order allow,deny

Allow from all

AllowOverride FileInfo 

&lt;/Directory&gt; 

DocumentRoot "D:/work"

ServerName "www.app.com"

&lt;/VirtualHost&gt;

.htaccess文件 放在project目录下面 就是每个项目目录下面，这样就会访问同级目录

index.php文件

index.php 目录下.htaccess文件:

RewriteEngine On

 

\# uncomment the following line, if you are having trouble

\# getting no\_script\_name to work

#RewriteBase /

 

\# we skip all files with .something

#RewriteCond %{REQUEST\_URI} \\..+$

#RewriteCond %{REQUEST\_URI} !\\.html$

#RewriteRule .* - \[L]

 

\# we check if the .html version is here (caching)

RewriteRule ^$ index.html \[QSA]

RewriteRule ^(\[^.]+)$ $1.html \[QSA]

RewriteCond %{REQUEST\_FILENAME} !-f

 

\# no, so we redirect to our front web controller

RewriteRule ^(.\*)$ index.php \[QSA,L]

\------------------------------------------------------------

程序中使用url\_for()方式

模板中示示例 我们还是以CURD方式 

&lt;td&gt;&lt;a href="&lt;?php echo url\_for("curd/edit/id/".$value\['bookid'])?&gt;"&gt;编辑&lt;/a&gt;&lt;/td&gt;

&lt;td&gt;&lt;a href="&lt;?php echo url\_for("curd/delete/id/".$value\['bookid'])?&gt;"&gt;删除&lt;/a&gt;&lt;/td&gt;

下载后在并在apache设置www.app.com 在c:/windows/system

http://www.tjwzjs.cn/queryphp/project/curd/index

是不是可以显示内容了

如果显示了 在framework\\config\\inc.ini.php 文件中把下面这行内容去掉注释

//$config\['html']='.html';//开启.html结尾url

http://www.tjwzjs.cn/queryphp/project/curd/index.html 访问

是不是可以看到内容了

所有链接都带.html结尾了。那我们有时候想不要.html结尾怎么办

&lt;a href="&lt;?php echo url\_for("curd/delete/id/".$value\['bookid'],true)?&gt;"&gt;删除&lt;/a&gt;

url\_for(url,true);方式 表示不要html结尾

删除会变成这样子

http://www.tjwzjs.cn/queryphp/project/curd/delete/id/2 

原文来源：[http://tjwzjs.cn/news/knowledge/2012/1210/56.html](http://tjwzjs.cn/news/knowledge/2012/1210/56.html "PHP框架queryphp教程：入门九 如何去掉index.php")