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重寫模塊,雙擊展開面板,能夠看到相應的功能


相關文章
相關標籤/搜索