ThinkPHP5 隱藏介面裡面的index.php

來源:互聯網
上載者:User

標籤:

隱藏index.php

官方介紹是這樣的:http://www.kancloud.cn/thinkphp/thinkphp5_quickstart/145250

可以去掉URL地址裡面的入口檔案index.php,但是需要額外配置WEB伺服器的重寫規則。

Apache為例,需要在入口檔案的同級添加.htaccess檔案(官方預設內建了該檔案),內容如下:

<IfModule mod_rewrite.c>Options +FollowSymlinks -MultiviewsRewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

接下來就可以使用下面的URL地址訪問了

http://tp5.com/index/index/indexhttp://tp5.com/index/index/hello

如果你使用的apache版本使用上面的方式無法正常隱藏index.php,可以嘗試使用下面的方式配置.htaccess檔案:

<IfModule mod_rewrite.c>Options +FollowSymlinks -MultiviewsRewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]</IfModule>

但是還是不行,查到這麼一篇文章(http://bbs.php100.com/simple/?t300372.html):
Apache Rewrite 擬靜態配置
1、mod_rewrite 簡介和配置
Rewirte主要的功能就是實現URL的跳轉和隱藏真真實位址,基於Perl語言的正則
運算式規範。平時協助我們實現擬靜態,擬目錄,網域名稱跳轉,防止盜鏈等
如一個普通訪問地址為  
   */php100.php?id=2
可以轉成:
   */PHP100_2.html
或轉成:
   */PHP100_2/

Apache配置:
支援httpd.conf 配置和目錄 .htaccess配置
啟用rewrite
# LoadModule rewrite_module modules/mod_rewrite.so
去除前面的 #
LoadModule rewrite_module modules/mod_rewrite.so
啟用.htaccess
AllowOverride None    修改為: AllowOverride All


2、mod_rewrite 規則的使用
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.php100.com  [NC]
RewriteRule   ^/(.*) http://www.php100.com/ [L]
啟動rewrite引擎 判斷主機 跳轉到
RewriteEngine on
RewriteRule ^/test([0-9]*).html$ /test.php?id=$1
RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]


3、mod_rewrite 規則修正符
1) R 強制外部重新導向
2) F 禁用URL,返回403HTTP狀態代碼。
3) G 強制URL為GONE,返回410HTTP狀態代碼。
4) P 強制使用代理轉寄。
5) L 表明當前規則是最後一條規則,停止分析以後規則的重寫。
6) N 重新從第一條規則開始運行重寫過程。
7) C 與下一條規則關聯

如果規則匹配則正常處理,以下修正符無效

8) T=MIME-type(force MIME type) 強制MIME類型
9) NS  只用於不是內部子請求
10) NC 不區分大小寫
11) QSA 追加請求字串
12) NE 不在輸出轉義特殊字元   \%3d$1  等價於 =$1
-----------------------------------------------------------------------------
也就是最後還要補充這麼處理:

把 #LoadModule rewrite_module modules/mod_rewrite.so 前面的#去掉,
再把許可權AllowOverride None都改為AllowOverride All ,重啟apache

ThinkPHP5 隱藏介面裡面的index.php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.