第一步 : 不管是 apache 還是 nginx ,想要隱藏 Index.php 文件,需要打開 urlManager 組件的配置,在進行后續的操作
04 | 'enablePrettyUrl' => true, |
05 | 'showScriptName' => false, |
06 | 'enableStrictParsing' => false, |
第二步 :
nginx 下 :
配置文件 nginx.conf 內容如下 :
04 | error_log logs/error.log; |
10 | worker_connections 10240; |
16 | default_type application/octet-stream; |
18 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
19 | '$status $body_bytes_sent "$http_referer" ' |
20 | '"$http_user_agent" "$http_x_forwarded_for"' ; |
22 | log_format log_json '{ "@timestamp": "$time_local", ' |
23 | '"remote_addr": "$remote_addr", ' |
24 | '"referer": "$http_referer", ' |
25 | '"request": "$request", ' |
27 | '"bytes": $body_bytes_sent, ' |
28 | '"agent": "$http_user_agent", ' |
29 | '"x_forwarded": "$http_x_forwarded_for", ' |
30 | '"up_addr": "$upstream_addr",' |
31 | '"up_host": "$upstream_http_host",' |
32 | '"up_resp_time": "$upstream_response_time",' |
33 | '"request_time": "$request_time"' |
37 | access_log logs/access.log; |
43 | keepalive_timeout 200; |
44 | client_max_body_size 200M; |
項目域名的配置整體是放在 vhost 這個目錄下面,改目錄下其中一個文件的內容
06 | root /home/centos/www/youdai-api/bird/web; |
08 | access_log logs/youdaiApi.access.log log_json; |
09 | error_log logs/youdaiApi.error.log; |
12 | try_files $uri $uri/ /index.php?$args; |
17 | fastcgi_pass 127.0.0.1:9000; |
18 | fastcgi_index index.php; |
19 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
20 | include fastcgi_params; |
apche 下 : 偽靜態配置
入口文件的同級目錄下,放置 .htaccess 文件

內容如下 :
2 | RewriteCond %{REQUEST_FILENAME} !-d |
3 | RewriteCond %{REQUEST_FILENAME} !-f |
4 | RewriteRule ^(.*)$ index.php?/ $1 [QSA,PT,L] |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。