yii2 url重寫并隱藏index.php方法
第一步 : 不管是 apache 還是 nginx ,想要隱藏 Index.php 文件,需要打開 urlManager 組件的配置,在進(jìn)行后續(xù)的操作
[ ‘components' => [ 'urlManager' => [ 'enablePrettyUrl' => true,//開啟美化URL 'showScriptName' => false,//是否顯示腳本名稱:index.php,同時(shí)應(yīng)該配置 Web 服務(wù) 'enableStrictParsing' => false,//是否開啟嚴(yán)格解析 //'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; }
項(xiàng)目域名的配置整體是放在 vhost 這個(gè)目錄下面,改目錄下其中一個(gè)文件的內(nèi)容
server { listen 80; server_name 域名; # 項(xiàng)目 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)配置
入口文件的同級(jí)目錄下,放置 .htaccess 文件
內(nèi)容如下 :
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
PHP根據(jù)傳入?yún)?shù)合并多個(gè)JS和CSS文件的簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要介紹了PHP合并多個(gè)JS和CSS文件的簡(jiǎn)單實(shí)現(xiàn),本文使用了一種比較簡(jiǎn)單的方法,重在揭示實(shí)現(xiàn)原理,需要的朋友可以參考下2014-06-06PHP連接和操作MySQL數(shù)據(jù)庫(kù)基礎(chǔ)教程
這篇文章主要介紹了PHP連接和操作MySQL數(shù)據(jù)庫(kù)基礎(chǔ)教程,本文講解了mysql擴(kuò)展、連接數(shù)據(jù)庫(kù)、與數(shù)據(jù)庫(kù)交互等內(nèi)容,需要的朋友可以參考下2014-09-09PHP學(xué)習(xí)記錄之面向?qū)ο螅∣bject-oriented programming,OOP)基礎(chǔ)【接口、抽象類、靜態(tài)方法等
這篇文章主要介紹了PHP學(xué)習(xí)記錄之面向?qū)ο螅∣bject-oriented programming,OOP)基礎(chǔ),結(jié)合實(shí)例形式分析了PHP面向?qū)ο蟪绦蛟O(shè)計(jì)中接口、抽象類、靜態(tài)方法等相關(guān)概念、原理、用法與操作注意事項(xiàng),需要的朋友可以參考下2019-12-12php實(shí)現(xiàn) master-worker 守護(hù)多進(jìn)程模式的實(shí)例代碼
這篇文章主要介紹了php實(shí)現(xiàn) master-worker 守護(hù)多進(jìn)程模式的實(shí)例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-07-07在服務(wù)端進(jìn)行目錄建立、刪除,文件上傳、刪除的過(guò)程的php代碼
下面的php代碼具有查看服務(wù)器端目錄和文件,刪除文件夾等操作,是學(xué)習(xí)php文件操作不錯(cuò)的參考資料2008-09-09CI框架無(wú)限級(jí)分類+遞歸的實(shí)現(xiàn)代碼
CodeIgniter是一個(gè)輕量級(jí)但功能強(qiáng)大的PHP框架,基于MVC設(shè)計(jì)模式,提供了一套豐富的類庫(kù),簡(jiǎn)單易學(xué),高效實(shí)用。下面給大家介紹CI框架無(wú)限級(jí)分類+遞歸的實(shí)現(xiàn)代碼,感興趣的朋友參考下吧2016-11-11PHP實(shí)現(xiàn)一個(gè)二維碼同時(shí)支持支付寶和微信支付的示例
這篇文章主要介紹了PHP實(shí)現(xiàn)一個(gè)二維碼同時(shí)支持支付寶和微信支付的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02php實(shí)現(xiàn)兼容2038年后Unix時(shí)間戳轉(zhuǎn)換函數(shù)
這篇文章主要介紹了php實(shí)現(xiàn)兼容2038年后Unix時(shí)間戳轉(zhuǎn)換函數(shù),使用方法和就的函數(shù)一樣,非常實(shí)用,推薦給大家,希望大家能夠喜歡。2015-03-03PHP結(jié)合Mysql數(shù)據(jù)庫(kù)實(shí)現(xiàn)留言板功能
這篇文章主要介紹了PHP結(jié)合Mysql數(shù)據(jù)庫(kù)實(shí)現(xiàn)留言板功能的相關(guān)資料,需要的朋友可以參考下2016-03-03