隐藏的index.php

PS:这里说的入口文件指的是公共/ index.php文件,配置文件就在这个目录下

可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。

Apache为例,在需要文件入口的同级添加.htaccess文件(官方默认自带了该文件),内容如下:

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

如果用的phpstudy,规则如下:

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$]
</IfModule>

如果index.php文件存放在public中,规则如下:

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php [L,E=PATH_INFO:$]
</IfModule>

接下来就可以使用下面的URL地址访问了

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

如果使用你的apache版本使用上面的方式无法正常隐藏index.php,尝试可以使用下面的方式配置.htaccess文件:

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

如果访问出现404的话,请修改配置文件vhosts-ini,原因请参考官方文档:https://www.kancloud.cn/manual/thinkphp5/177576

location / {
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
#autoindex on;
}

参考:https://blog.csdn.net/nookl/article/details/80039996

TP5配置隐藏入口index.php文件的更多相关文章

  1. TP5配置隐藏入口index.php文件,Apache/phpstudy

    一,找到/public/.htaccess文件,如果你的入口文件已经移动到根目录下,那么你的.htaccess文件也要剪切到根目录下,总之要确保.htaccess跟入口的index.php保持同级. ...

  2. 【TP3.2.X】(同样适用于OT) 设置单入口index.php文件,区分PC/WAP/Wechat 三个终端

    1.目的:本教程适用于 OneThink1.0.或者TP3.2.X 系列,达到单入口index.php文件,区分PC/WAP/Wechat 三个终端 2.启发至 : http://www.thinkp ...

  3. Nginx配置 隐藏入口文件index.php

    Nginx配置文件里放入这段代码 server { location / { index index.php index.html index.htm l.php; autoindex on; if ...

  4. Nginx如何来配置隐藏入口文件index.php(代码)

    Nginx配置文件里放入这段代码 server { location / { index index.php index.html index.htm l.php; autoindex on; if ...

  5. TP5中隐藏入口文件的问题 - CSDN博客

    使用phpstudy和linux部署的时候 tp5中的官方说明是在入口文件的同级目录下添加一个.htaccess文件 文件内容如下: <IfModule mod_rewrite.c>Opt ...

  6. nginx下TP5 隐藏入口文件+支持pathinfo模式+配置多项目根目录

    首先说下项目目录情况  跟目录/usr/share/nginx/html/(别说怎么这么深  0.0) html文件夹下面两个目录 pssh  pssh_shop 两个tp5项目分别对应两个二级域名 ...

  7. PHPStudy+PHPStorm下配置隐藏项目入口文件

    img { max-width: 100% } 默认情况下项目入口文件是站点根目录下index.php文件,一般程序启动时通过这个文件,定义文件路径,配置重要节点(比如是否开启调试模式),注册路由等, ...

  8. tp5隐藏入口文件(基于nginx)

    location / {             try_files $uri $uri/ /index.php?$query_string; #这项配置解决访问根目录以外路径报404的错误      ...

  9. PHP隐藏入口脚本文件index.php

    一.nginx下 隐藏入口文件时,配置nginx 首先得开启nginx pathinfo模式: location ~ \.php { #去掉$ root E:/phpStudy/WWW/tp/publ ...

随机推荐

  1. SUCTF 2018——Anonymous(php匿名函数 \x00lambda_)

    题目地址:http://45.76.173.177:23334/ <?php $MY = create_function("","die(`cat flag.php ...

  2. 3 CVE-2017-11882漏洞分析

    CVE-2017-11882漏洞分析 操作系统:Windows7 32/64位 专业版.Linux 软件:office 2003 sp3 工具:OD.IDA.Python模块.msfconsole 1 ...

  3. 分布式session的解决方案

    1.Nginx的ip_hash,对应tomcat的session,由tomcat保存 缺点:一旦tomcat单点挂机,session消失 2.session在tomcat之间复制, 缺点:保存全局se ...

  4. Excel分列,Excel 列拆分,Excel根据分隔符号拆分某列

    解决方案: https://zhidao.baidu.com/question/572807483.html 步骤:数据--分列--下一步--其它---下一步-- 注意的此操作会覆盖当前列和后n列(根 ...

  5. MySQL——基本概念

    1.数据库:是一个长期存储在计算机内的.有组织的.有共享的.统一管理的数据集合.它是一个按数据结构来存储的和管理数据的计算机软件系统,即数据库包含两层含义:保管数据的“仓库”,以及数据管理的方法和技术 ...

  6. MySQL基本库表管理

    基本管理指令 mysql登陆 第一种 [root@wei ~]# mysql -u root -p 第二种(带参输入) [root@wei ~]# mysql -uroot -proot 注意:每个命 ...

  7. lua使用ffi调用c程序的函数

    参考: https://blog.csdn.net/weiwangchao_/article/details/16880401   http://luajit.org/ext_c_api.html h ...

  8. docker学习-qiang

    docker优势 轻量级.资源损耗少.启动快.性能高.只能运行linux系统 容器技术发展历程 1.chroot技术 新建一个子系统(拥有自己完整的系统文件) ldd /bin/ls(查看ls命令依赖 ...

  9. linux下使用shell发送http请求

    一.curl 1. get请求 curl命令默认下就是使用get方式发送http请求. curl www.baidu.com 2. post请求 使用-d参数,形式如下: curl -d " ...

  10. 【AICC】2019训练营笔记

    1.AI 人工的方法在机器上实现智能:机器学习.计算机视觉.规划决策.自然语言处理.认知推理.高效搜索 2.三大学派 符号主义 连接主义:CNN 行为主义 3.两条路线 结构模仿 功能模仿 4.AI芯 ...