您的位置:首页 > 编程语言 > PHP开发

ThinkPHP去除url中的index.php

2016-02-17 00:00 691 查看
一、apache服务器

1.httpd.conf配置文件中加载了mod_rewrite.so模块 //在APACHE里面去配置

#LoadModule rewrite_module modules/mod_rewrite.so把前面的警号去掉

2.AllowOverride None 讲None改为 All //在APACHE里面去配置 (注意其他地方的AllowOverride也统统设置为ALL)
<Directory "D:/server/apache/cgi-bin">
AllowOverride none 改 AllowOverride ALL
Options None
Order allow,deny
Allow from all
</Directory>

3.确保URL_MODEL设置为2,在项目的配置文件里写
return Array(
'URL_MODEL' => '2',
);

4 .htaccess文件必须放到跟目录下
这个文件里面加:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
补充:在windows下不能建立以点开头的文件,你可以先随便建立一个文件

然后在DOS在操作 rename xxxx.xxxx .htaccess

转载来源 地址: http://sjolzy.cn/ThinkPHP-remove-the-indexphp-url.html

二、IIS7.5服务器

1、windows 下的地址重写组件基本上都是收费或有限制,从windows server 2008开始官方提供了自己的重写组件,下载地址:http://www.iis.net/downloads/microsoft/url-rewrite。

规则文件要写在网站根目录的web.config中,重写规则可以由.htaccess导入过来,会变成web.config文件,

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="system" patternSyntax="ECMAScript">
<match url="^.*system/(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/system/index.php?s={R:1}" appendQueryString="true" />
</rule>
<rule name="auth" patternSyntax="ECMAScript">
<match url="^.*auth/(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/auth/index.php?s={R:1}" appendQueryString="true" />
</rule>
<rule name="main" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?s={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>

如上是简单的thinkphp的根目录跟子目录省去index.php的方法,这个实现在apache中简单多了,直接将.htaccess拷贝到根目录及各个子目录就可以了

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>

2.打开官方下载地址,将页面拖到最底下,根据自己的需求选择相应的版本,有语言及32位、64位区分



3.双击同意协议安装



4.安装完成后,开始-管理工具-Internet 信息服务(IIS)管理器 即可找到URL重写模块,双击展开面板,可以看到相应的功能





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: