当前位置: 首页 > 后端技术 > PHP

yii2url重写隐藏index.php方法

时间:2023-03-29 19:06:51 PHP

第一步:不管是apache还是nginx,如果要隐藏Index.php文件,需要打开urlManager组件的配置,进行后续操作第二步:nginx下:配置文件内容nginx.conf如下:usercentos;worker_processes4;error_log日志/error.log;pid日志/nginx.pid;events{worker_connections10240;}http{includemime.types;default_type应用程序/八位字节流;log_formatmain'$remote_addr-$remote_user[$time_local]"$request"''$status$body_bytes_sent"$http_referer"''"$http_user_agent""$http_x_forwarded_for"';log_formatlog_json'{"@timestamp":"$time_local",''"remote_addr":"$remote_addr",''"referer":"$http_referer",''"request":"$request",''"status":$status,''"bytes":$body_bytes_sent,''"agent":"$http_user_agent",''"x_forwarded":"$http_x_forwarded_for",''"up_addr":"$upstream_addr",''"up_host":"$upstream_http_host",''"up_resp_time":"$upstream_response_time",''"request_time":"$request_time"''}';access_loglogs/access.log;sendfileon;#tcp_nopushon;#keepalive_timeout0;keepalive_timeout200;client_max_body_size200M;gzipon;includevhost/*.conf;目录服务器中文件之一的内容{listen80;server_name域名;#项目index.php地址root/home/centos/www/youdai-api/bird/web;access_loglogs/youdaiApi.access.loglog_json;error_loglogs/youdaiApi.error.log;location/{try_files$uri$uri//index.php?$args;indexindex.php;}location~\.php${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;包括fastcgi_params;}location~/\.ht{全部拒绝;onRewriteCond%{REQUEST_FILENAME}!-dRewriteCond%{REQUEST_FILENAME}!-fRewriteRule^(.*)$index.php?/$1[QSA,PT,L]