使用Z-PHP框架并隐藏index.php亲测有用

使用Z-PHP框架并隐藏index.php亲测有用

精选文章moguli202024-12-13 12:01:1626A+A-

1、使用apache服务环境:

在public目录下新建.htaccess文件,内容如下:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks -Multiviews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

按官网文档说明是:一个应用目录对应一个入口文件;我这就不这样,直接在public目录下新建admin目录,再新建index.php文件,也新建上面的.htaccess文件,这样也可以隐藏index.php并方便增加其它应用目录。

<?php
// admin目录下的index.php
define('APP_NAME', 'admin');
require '../../core.php';
AppRun(__DIR__, [
  'nec\z\debug',
  'nec\z\router',
  'nec\z\lang',
  'nec\z\view',
]);

2、nginx服务环境:

如果你的是虚拟主机,就找到相应的域名配置文件,在server {} 括号内增加内容:

location / {
  index index.php index.html;
  rewrite ^/(.*)$ /index.php/$1 last;
  autoindex  off;
}

location /admin/ {
  index index.php index.html;
  rewrite ^/admin/(.*)$ /admin/index.php/$1 last;
	autoindex  off;
}

这样也能实现与apache下一样的功能,只是在nginx下如果增加user等项目,又得增加 location /user/ {},感觉不方便,不知道有没有办法能不能写在一起,请高手帮忙,谢谢!

Z-PHP手册地址:https://www.showdoc.com.cn/zphp5/

Z-PHP是特别轻量的PHP框架,如果你也喜欢请点赞关注下,我们一起学习并提高。

点击这里复制本文地址 以上内容由莫古技术网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

莫古技术网 © All Rights Reserved.  滇ICP备2024046894号-2