ThinkPHP3.2.2中開啟REWRITE模式

來源:互聯網
上載者:User

標籤:檔案中   director   cto   訪問   bsp   目錄許可權   模組   地址   項目   

1、

在項目設定檔(\Application\Common\Conf\config.php)中配置URL模式

1 <?php2 return array(3     //URL模式4     ‘URL_MODEL‘ => 2,
5   ‘URL_ROUTER_ON‘   =>  true,//預設fllse,   // 是否開啟URL路由
6 );

添加.htaccess檔案  內容如下:


<IfModule mod_rewrite.c>
                       RewriteEngine on
                       RewriteCond %{REQUEST_FILENAME} !-d
                       RewriteCond %{REQUEST_FILENAME} !-f
                       RewriteRule ^(.*)$ index.PHP/$1 [QSA,PT,L]
</IfModule>

 要是想隱藏admin.php後台入口的, 要加上下面這幾行

RewriteRule admin$ ./admin.php [NC,L]
RewriteRule admin/$ ./admin.php [NC,L]
RewriteRule admin/(.*)$ admin.php/$1 [NC,QSA,PT,L]

 最後變成

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

                       RewriteRule admin$ ./admin.php [NC,L]
                      RewriteRule admin/$ ./admin.php [NC,L]
                      RewriteRule admin/(.*)$ admin.php/$1 [NC,QSA,PT,L]
</IfModule>

2、

在ThinkPHP的URL模式中,REWRITE模式去掉了URL地址中的入口檔案index.php,但是需要額外配置Web伺服器的重寫規則才能正確訪問。

Apache伺服器可以通過開啟rewrite模組和分布式設定檔(.htaccess)的支援以實現ThinkPHP中的REWRITE模式。具體步驟如下:

  1.開啟Apache設定檔(httpd.conf),將載入rewrite模組的指令取消注釋:

1 LoadModule rewrite_module modules/mod_rewrite.so

      2.修改目錄許可權,啟用分布式設定檔:

1 <Directory />2     Options FollowSymLinks3     AllowOverride All4     Order deny,allow5     Allow from all6 </Directory>

       在上面代碼中 AllowOverride All 表示啟用分布式設定檔。

    ThinkPHP中內建的 .htaccess 檔案中已經寫好了URL重寫規則,通過上述配置後,就可以使用REWRITE模式進行訪問了。

 

---轉寄並完善

ThinkPHP3.2.2中開啟REWRITE模式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.