ThinkPHP框架里隱藏index.php
本文所寫的配置在ThinkPHP3.2.2上測試過。按理也兼容其它版本。
首先修改配置文件:
'URL_CASE_INSENSITIVE' => true, // 默認(rèn)false 表示URL區(qū)分大小寫 true則表示不區(qū)分大小寫
'URL_MODEL' => 2, // URL訪問模式,可選參數(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不存在,就訪問$uri/;如果$uri/還不存在,訪問/index.php?s=$uri&$args。可以后面跟很多個(gè)。
try_files 語法: try_files file1 [file2 ... filen] fallback 默認(rèn)值: 無 作用域: location
再例如:
try_files $uri = 404
什么意思呢?uri不能成功訪問,那好,那就給你個(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通過一個(gè)入口文件如何區(qū)分移動端和PC端
- ThinkPHP中url隱藏入口文件后接收alipay傳值的方法
- 淺談thinkphp的nginx配置,以及重寫隱藏index.php入口文件方法
- thinkphp3.2中Lite文件替換框架入口文件或應(yīng)用入口文件的方法
- Thinkphp5 如何隱藏入口文件index.php(URL重寫)
- 在thinkphp5.0路徑中實(shí)現(xiàn)去除index.php的方式
- thinkphp隱藏index.php/home并允許訪問其他模塊的實(shí)現(xiàn)方法
- Nginx配置PATHINFO隱藏thinkphp index.php
- 修改apache配置文件去除thinkphp url中的index.php
- Thinkphp 框架基礎(chǔ)之入口文件功能、定義與用法分析
相關(guān)文章
CI框架入門示例之?dāng)?shù)據(jù)庫取數(shù)據(jù)完整實(shí)現(xiàn)方法
這篇文章主要介紹了CI框架入門示例的數(shù)據(jù)庫取數(shù)據(jù)完整實(shí)現(xiàn)方法,包含了配置、建表與實(shí)現(xiàn)MVC的完整過程,需要的朋友可以參考下2014-11-11
Laravel 6.2 中添加了可調(diào)用容器對象的方法
Laravel小組上周發(fā)布了v6.2.0 版本,接下來通過本文給大家分享Laravel 6.2 中添加了可調(diào)用容器對象的方法,需要的朋友可以參考下2019-10-10
淺析PHP反序列化中過濾函數(shù)使用不當(dāng)導(dǎo)致的對象注入問題
這篇文章主要介紹了PHP反序列化中過濾函數(shù)使用不當(dāng)導(dǎo)致的對象注入問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-02-02
Yii2實(shí)現(xiàn)同時(shí)搜索多個(gè)字段的方法
這篇文章主要介紹了Yii2實(shí)現(xiàn)同時(shí)搜索多個(gè)字段的方法,結(jié)合實(shí)例形式分析了Yii2中同時(shí)搜索多個(gè)字段所使用的函數(shù)與具體使用方法,需要的朋友可以參考下2016-08-08
php刪除數(shù)組指定元素實(shí)現(xiàn)代碼
這篇文章主要介紹了php刪除數(shù)組指定元素實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05
PHP網(wǎng)頁游戲?qū)W習(xí)之Xnova(ogame)源碼解讀(四)
這篇文章主要介紹了PHP網(wǎng)頁游戲Xnova(ogame)源碼解讀的用戶登錄頁面,需要的朋友可以參考下2014-06-06

