yii2 url重寫并隱藏index.php方法
第一步 : 不管是 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 內(nèi)容如下 :
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 這個目錄下面,改目錄下其中一個文件的內(nèi)容
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 文件
內(nèi)容如下 :
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
PHP根據(jù)傳入?yún)?shù)合并多個JS和CSS文件的簡單實現(xiàn)
這篇文章主要介紹了PHP合并多個JS和CSS文件的簡單實現(xiàn),本文使用了一種比較簡單的方法,重在揭示實現(xiàn)原理,需要的朋友可以參考下2014-06-06PHP學習記錄之面向?qū)ο螅∣bject-oriented programming,OOP)基礎【接口、抽象類、靜態(tài)方法等
這篇文章主要介紹了PHP學習記錄之面向?qū)ο螅∣bject-oriented programming,OOP)基礎,結合實例形式分析了PHP面向?qū)ο蟪绦蛟O計中接口、抽象類、靜態(tài)方法等相關概念、原理、用法與操作注意事項,需要的朋友可以參考下2019-12-12php實現(xiàn) master-worker 守護多進程模式的實例代碼
這篇文章主要介紹了php實現(xiàn) master-worker 守護多進程模式的實例代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值 ,需要的朋友可以參考下2019-07-07在服務端進行目錄建立、刪除,文件上傳、刪除的過程的php代碼
下面的php代碼具有查看服務器端目錄和文件,刪除文件夾等操作,是學習php文件操作不錯的參考資料2008-09-09PHP實現(xiàn)一個二維碼同時支持支付寶和微信支付的示例
這篇文章主要介紹了PHP實現(xiàn)一個二維碼同時支持支付寶和微信支付的示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-02-02php實現(xiàn)兼容2038年后Unix時間戳轉(zhuǎn)換函數(shù)
這篇文章主要介紹了php實現(xiàn)兼容2038年后Unix時間戳轉(zhuǎn)換函數(shù),使用方法和就的函數(shù)一樣,非常實用,推薦給大家,希望大家能夠喜歡。2015-03-03PHP結合Mysql數(shù)據(jù)庫實現(xiàn)留言板功能
這篇文章主要介紹了PHP結合Mysql數(shù)據(jù)庫實現(xiàn)留言板功能的相關資料,需要的朋友可以參考下2016-03-03