ThinkPHP去除url中的index.php

1、apache服务器php

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下不能创建以点开头的文件,你能够先随便创建一个文件
html

而后在DOS在操做 rename xxxx.xxxx   .htaccessweb



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

2、IIS7.5服务器apache

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

规则文件要写在网站根目录的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拷贝到根目录及各个子目录就能够了app

<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位区分
ide

3.双击赞成协议安装
工具

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


相关文章
相关标签/搜索