隐藏的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. Bloom’S Taxonomy

    引用:https://www.learning-theories.com/blooms-taxonomy-bloom.html Bloom's Taxonomy is a model that is ...

  2. i春秋——“百度杯”CTF比赛 十月场——EXEC(命令执行、带外通道传输数据)

    查看源码得知由vim编写,所以查找备份以及交换文件 找到 /.index.php.swp ,下载后用vim -r恢复该文件即可得到源码 1 <html> 2 <head> 3 ...

  3. c# 根据域名的到对应的IP

    今天做了域名解析,由于项目里要用到域名对应的ip 所以做了这个小程序 private void button_Net_Click(object sender, EventArgs e)        ...

  4. sap设置SE38编辑器背景色

    1.SE38,随便找个程序进入,编辑模式. 点击客户端最右下角的文件夹图标: 2.设置normal 背景颜色: 3.退出,重新进就可以了. 这里很多其他类型的颜色和字体设置,根据个人爱好调整.

  5. Zabbix 添加内存告警

    1.在Template OS Linux模板创建item Configuration-->Templates-->Template OS Linux-->items-->cre ...

  6. 实验十四 团队项目评审&个人学习总结

    实验十四 课程学习总结 项目 内容 这个作业属于哪个课程 (https://www.cnblogs.com/nwnu-daizh/) 这个作业的要求在哪里 (https://www.cnblogs.c ...

  7. VMware下安装Ubuntu虚拟机

    ubuntu系统是以桌面应用为主的.当下最火的linux操作系统,具有实用的界面,并且完全免费. 在Ubuntu的 Linux 世界里,已经不再只是简陋的界面+命令行,而是一款华丽时尚且无比实用的操作 ...

  8. 08-人脸识别-FaceNet-classify.py代码阅读(说明见注释)

    """An example of how to use your own dataset to train a classifier that recognizes pe ...

  9. USACO Mooo Moo

    洛谷 P2214 [USACO14MAR]哞哞哞Mooo Moo 洛谷传送门 JDOJ 2416: USACO 2014 Mar Silver 3.Mooo Moo JDOJ传送门 Descripti ...

  10. PHP 多个字段自增或者自减

    //自增$res=Db::name('accessories') ->where('id',$req['id']) ->inc('number',$req['number']) -> ...