入口文件 index.php 隱藏
在PHP的web項目中器予,問了隱藏項目的開發(fā)語言杠袱,我們首先會選擇把項目的入口文件index.php(如果做了特殊配置,特殊處理)在URL中隱藏掉迂卢。
當然部署中還需要隱藏其他信息茶宵,例如服務(wù)器的類型和版本,開發(fā)語言(PHP)的版本等财破。
隱藏方法
apache
apache 作為web服務(wù)器掰派,跟PHP是老搭檔了,以下是apache下隱藏index.php方法
- 第一步
apache一般安裝內(nèi)置了rewrite模塊左痢,但是默認未啟用狀態(tài)靡羡;要啟用rewrite模塊:
在httpd.conf中找到以下信息,去掉注釋”#“號
LoadModule rewrite_module modules/mod_rewrite.so
- 第二步
在項目入口index.php文件同級目錄新建一個.htaccess文件俊性,文件內(nèi)容如下:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
nginx
nginx 作為輕量級高性能的HTTP和反向代理服務(wù)略步,在web應(yīng)用中占比越來越大;
隱藏入口文件定页,需要修改nginx.conf對應(yīng)項目的server內(nèi)配置:
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;
}
}
...
}