yii如何隱藏index.php-創(chuàng)新互聯(lián)

小編給大家分享一下yii如何隱藏index.php,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

為企業(yè)提供成都網(wǎng)站設(shè)計、成都網(wǎng)站制作、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)營銷推廣、競價托管、品牌運(yùn)營等營銷獲客服務(wù)。成都創(chuàng)新互聯(lián)擁有網(wǎng)絡(luò)營銷運(yùn)營團(tuán)隊(duì),以豐富的互聯(lián)網(wǎng)營銷經(jīng)驗(yàn)助力企業(yè)精準(zhǔn)獲客,真正落地解決中小企業(yè)營銷獲客難題,做到“讓獲客更簡單”。自創(chuàng)立至今,成功用技術(shù)實(shí)力解決了企業(yè)“網(wǎng)站建設(shè)、網(wǎng)絡(luò)品牌塑造、網(wǎng)絡(luò)營銷”三大難題,同時降低了營銷成本,提高了有效客戶轉(zhuǎn)化率,獲得了眾多企業(yè)客戶的高度認(rèn)可!

yii隱藏index.php的方法:首先在配置文件main.php中添加urlManager;然后在index.php同級目錄下新建.htaccess文件;最后配置nginx.conf和vhosts.conf即可。

Yii 隱藏 index.php(Apache + nginx)

1、在配置文件 main.php 中添加

'urlManager' => [//用于URL路徑化'enablePrettyUrl' => true,//指定是否在URL在保留入口腳本 
index.php'showScriptName' => false,],

2.1、Apache 配置

同時還要在index.php同級目錄下新建.htaccess文件

#表示開啟重寫引擎
RewriteEngine on
#請求的文件或路徑是不存在的,如果文件或路徑存在將返回已經(jīng)存在的文件或路徑
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

.htaccess文件解釋

概述來說,htaccess文件是Apache服務(wù)器中的一個配置文件,它負(fù)責(zé)相關(guān)目錄下的網(wǎng)頁配置。

通過htaccess文件,可以幫我們實(shí)現(xiàn):網(wǎng)頁301重定向、自定義404錯誤頁面、改變文件擴(kuò)展名、 允許/阻止特定的用戶或者目錄的訪問、禁止目錄列表、配置默認(rèn)文檔等功能。

2.2、nginx 配置

① nginx.conf 配置

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 128k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 32k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_disable "MSIE [1-6].";
    server_names_hash_bucket_size 128;
    client_max_body_size     100m; 
    client_header_buffer_size 256k;
    large_client_header_buffers 4 256k;
    server {
        listen       80;
        server_name  localhost;
        #你的項(xiàng)目根目錄
        root   "D:/Program Files/phpStudy/WWW";
        location / {
            index  index.html index.htm index.php l.php;
           autoindex  off;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php(.*)$  {
            #你的項(xiàng)目根目錄
            root   "D:/Program Files/phpStudy/WWW";
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
    }
    include vhosts.conf;
}

② vhosts.conf 配置

server {
        listen       80;
        #你的虛擬主機(jī)名
        server_name  www.luluqi.com ;
        #虛擬主機(jī)根目錄
        root   "D:/Program Files/phpStudy/WWW/luluyii/web";
        location / {
            index  index.php index.html index.htm;
            #nginx ignore index.php
            if (!-e $request_filename){  
              rewrite ^/(.*) /index.php last;  
            }    
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
        
}

以上是“yii如何隱藏index.php”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

新聞名稱:yii如何隱藏index.php-創(chuàng)新互聯(lián)
本文鏈接:http://muchs.cn/article40/djijeo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、網(wǎng)站營銷、App設(shè)計、虛擬主機(jī)、軟件開發(fā)、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作