2019-03-19 10:32:18 2374瀏覽
PHP開發(fā)技術已經(jīng)被越來越多的人所喜愛,所以現(xiàn)在參加PHP培訓的人也在不斷的增加,本篇文章小編給大家分享一下yii2 url重寫并隱藏index.php方法,對PHP開發(fā)技術感興趣或者是想要學習PHP開發(fā)技術的小伙伴就隨小編一起來了解一下吧。
第一步 : 不管是apache 還是nginx ,想要隱藏Index.php 文件,需要打開urlManager 組件的配置,在進行后續(xù)的操作:
[ ‘components' => [ 'urlManager' => [ 'enablePrettyUrl' => true,//開啟美化URL 'showScriptName' => false,//是否顯示腳本名稱:index.php,同時應該配置 Web 服務 'enableStrictParsing' => false,//是否開啟嚴格解析 //'suffix' => '.html',//生成帶 .html 后綴的 URL 'rules' => [ ], ], ], ]
第二步:
nginx下:
配置文件 nginx.conf 內容如下:
user centos; worker_processes 4; error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 10240; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; log_format log_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_log logs/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 200; client_max_body_size 200M; gzip on; include vhost/*.conf; }
項目域名的配置整體是放在 vhost 這個目錄下面,改目錄下其中一個文件的內容
server { listen 80; server_name 域名; # 項目 index.php 地址 root /home/centos/www/youdai-api/bird/web; access_log logs/youdaiApi.access.log log_json; error_log logs/youdaiApi.error.log; location / { try_files $uri $uri/ /index.php?$args; index index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }
apche 下:偽靜態(tài)配置
入口文件的同級目錄下,放置 .htaccess 文件
內容如下:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
想要了解更多關于PHP開發(fā)方面內容的小伙伴,請關注扣丁學堂PHP培訓官網(wǎng)、微信等平臺,扣丁學堂IT職業(yè)在線學習教育有專業(yè)的PHP講師為您指導,此外扣丁學堂老師精心推出的PHP視頻教程定能讓你快速掌握PHP從入門到精通開發(fā)實戰(zhàn)技能。扣丁學堂PHP技術交流群:374332265。
【關注微信公眾號獲取更多學習資料】