ThinkPHP框架里隱藏index.php
本文所寫(xiě)的配置在ThinkPHP3.2.2上測(cè)試過(guò)。按理也兼容其它版本。
首先修改配置文件:
'URL_CASE_INSENSITIVE' => true, // 默認(rèn)false 表示URL區(qū)分大小寫(xiě) true則表示不區(qū)分大小寫(xiě)
'URL_MODEL' => 2, // URL訪問(wèn)模式,可選參數(shù)0、1、2、3,代表以下四種模式:
// 0 (普通模式); 1 (PATHINFO 模式); 2 (REWRITE 模式); 3 (兼容模式) 默認(rèn)為PATHINFO 模式
Nginx
推薦:
location / { try_files $uri $uri/ /index.php?s=$uri&$args; }
意思是:如果第一個(gè)$uri不存在,就訪問(wèn)$uri/;如果$uri/還不存在,訪問(wèn)/index.php?s=$uri&$args??梢院竺娓芏鄠€(gè)。
try_files 語(yǔ)法: try_files file1 [file2 ... filen] fallback 默認(rèn)值: 無(wú) 作用域: location
再例如:
try_files $uri = 404
什么意思呢?uri不能成功訪問(wèn),那好,那就給你個(gè)404吧。
但是在網(wǎng)上找到的文章大部分是這樣配置的:
location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?/$1 last; break; } }
實(shí)際上不可行。
Apache
在根目錄新建.htaccess文件:
<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule>
IIS環(huán)境
如果你的服務(wù)器環(huán)境支持ISAPI_Rewrite的話,可以配置httpd.ini文件,添加下面的內(nèi)容:
RewriteRule (.*)$ /index\.php\?s=$1 [I]
在IIS的高版本下面可以配置web.Config,在中間添加rewrite節(jié)點(diǎn):
<rewrite> <rules> <rule name="OrgPage" stopProcessing="true"> <match url="^(.*)$" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^(.*)$" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}” matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite>
附錄
Nginx完整配置文
test.com.conf server { listen 80; server_name test.com; index index.php index.html; root /wwwroot/test.com/; # unless the request is for a valid file (image, js, css, etc.), send to bootstrap location / { try_files $uri $uri/ /index.php?s=$uri&$args; } location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; set $path_info ""; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } location /status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 24h; } location ~ .*\.(js|css)?$ { expires 12h; } if ( $fastcgi_script_name ~ \..*\/.*php ) { return 403; } access_log logs/test.com_access.log main; error_log logs/test.com_error.log notice; }
- ThinkPHP入口文件設(shè)置及相關(guān)注意事項(xiàng)分析
- Thinkphp通過(guò)一個(gè)入口文件如何區(qū)分移動(dòng)端和PC端
- ThinkPHP中url隱藏入口文件后接收alipay傳值的方法
- 淺談thinkphp的nginx配置,以及重寫(xiě)隱藏index.php入口文件方法
- thinkphp3.2中Lite文件替換框架入口文件或應(yīng)用入口文件的方法
- Thinkphp5 如何隱藏入口文件index.php(URL重寫(xiě))
- 在thinkphp5.0路徑中實(shí)現(xiàn)去除index.php的方式
- thinkphp隱藏index.php/home并允許訪問(wèn)其他模塊的實(shí)現(xiàn)方法
- Nginx配置PATHINFO隱藏thinkphp index.php
- 修改apache配置文件去除thinkphp url中的index.php
- Thinkphp 框架基礎(chǔ)之入口文件功能、定義與用法分析
相關(guān)文章
windows的文件系統(tǒng)機(jī)制引發(fā)的PHP路徑爆破問(wèn)題分析
這篇文章主要介紹了windows的文件系統(tǒng)機(jī)制引發(fā)的PHP路徑爆破問(wèn)題分析,需要的朋友可以參考下2014-07-07Yii2.0使用阿里云OSS的SDK上傳圖片、下載、刪除圖片示例
本篇文章主要介紹了Yii2.0使用阿里云OSS的SDK上傳圖片、下載、刪除圖片示例,具有一定的參考價(jià)值,有興趣的可以了解一下2017-09-09PHP網(wǎng)頁(yè)游戲?qū)W習(xí)之Xnova(ogame)源碼解讀(十六)
這篇文章主要介紹了PHP網(wǎng)頁(yè)游戲Xnova(ogame)源碼解讀的攻擊任務(wù)頁(yè)面的代碼流程,需要的朋友可以參考下2014-06-06一次項(xiàng)目中Thinkphp繞過(guò)禁用函數(shù)的實(shí)戰(zhàn)記錄
這篇文章主要給大家介紹了一次項(xiàng)目中Thinkphp繞過(guò)禁用函數(shù)的實(shí)戰(zhàn)記錄,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2021-11-11詳解PHP中instanceof關(guān)鍵字及instanceof關(guān)鍵字有什么作用
這篇文章主要介紹了PHP中instanceof關(guān)鍵字詳解及instanceof關(guān)鍵字有什么作用的相關(guān)資料,需要的朋友可以參考下2015-11-11Thinkphp 框架擴(kuò)展之驅(qū)動(dòng)擴(kuò)展實(shí)例分析
這篇文章主要介紹了Thinkphp 框架擴(kuò)展之驅(qū)動(dòng)擴(kuò)展,結(jié)合實(shí)例形式分析了Thinkphp 框架驅(qū)動(dòng)擴(kuò)展相關(guān)原理、實(shí)現(xiàn)方法及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04