入口文件 index.php 隐藏

入口文件 index.php 隐藏

在PHP的web项目中,问了隐藏项目的开发语言,我们首先会选择把项目的入口文件index.php(如果做了特殊配置,特殊处理)在URL中隐藏掉。
当然部署中还需要隐藏其他信息,例如服务器的类型和版本,开发语言(PHP)的版本等。

隐藏方法

apache

apache 作为web服务器,跟PHP是老搭档了,以下是apache下隐藏index.php方法

  • 第一步

apache一般安装内置了rewrite模块,但是默认未启用状态;要启用rewrite模块:

在httpd.conf中找到以下信息,去掉注释”#“号

LoadModule rewrite_module modules/mod_rewrite.so 
  • 第二步

在项目入口index.php文件同级目录新建一个.htaccess文件,文件内容如下:

<IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

nginx

nginx 作为轻量级高性能的HTTP和反向代理服务,在web应用中占比越来越大;

隐藏入口文件,需要修改nginx.conf对应项目的server内配置:

server { listen 80; default_type text/plain; root /var/www/html; ... location / { index index.html index.htm index.php; #autoindex on; # 隐藏入口文件 if (!-e $request_filename) { #一级目录下 隐藏入口文件 rewrite ^/(.*)$ /index.php/$1 last; #域名下的二级目录 #rewrite ^/目录名/(.*)$ /目录名/index.php/$1 last; } } ...}

相关文章