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

时间:2022-03-08 01:57:53

默认情况下项目入口文件是站点根目录下index.php文件,一般程序启动时通过这个文件,定义文件路径,配置重要节点(比如是否开启调试模式),注册路由等,不管是为了伪静态还是为了url的美观,经常需要隐藏掉入口文件:

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

在apache服务模式下,是在项目根目录下,添加.htaccess并添加如下代码:

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

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

nginx服务模式下,更改nginx-conf文件中的Server->location配置节:

 server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main;
root "D:/SofrInstall/phpStudy/PHPTutorial/WWW/Practice/";
#location / {
# index index.html index.htm index.php l.php;
# autoindex off;
#}
location / {
if (!-e $request_filename){
rewrite ^/index.html/?$ /index.php?s= last;
rewrite ^(.*)$ /index.php?s=$ last;
break;
}
}

配置完成之后,保存文件重启服务生效:

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

参考地址:https://www.shiqidu.com/p/80