首頁 php框架 YII yii2如何隱藏index.php

yii2如何隱藏index.php

Aug 17, 2020 am 09:02 AM
index.php yii2

yii2隐藏index.php的方法:首先打开urlManager组件的配置;然后配置文件nginx.conf内容;接着将项目域名的配置整体放在vhost目录下;最后在入口文件的同级目录下放置“.htaccess”文件即可。

yii2如何隱藏index.php

推荐:《yii教程

yii2 url 重写 隐藏 index.php 方法

第一步  : 不管是  apache 还是  nginx ,想要隐藏 Index.php 文件,需要打开  urlManager  组件的配置,在进行后续的操作

yii2如何隱藏index.php

第二步 :

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 下 : 伪静态配置
入口文件的同级目录下,放置 .htaccess 文件

yii2如何隱藏index.php

内容如下 :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
登入後複製

以上是yii2如何隱藏index.php的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1672
14
CakePHP 教程
1428
52
Laravel 教程
1332
25
PHP教程
1276
29
C# 教程
1256
24
yii2 怎麼去掉jquery yii2 怎麼去掉jquery Feb 17, 2023 am 09:55 AM

yii2去掉jquery的方法:1、編輯AppAsset.php文件,註解掉變數$depends裡的「yii\web\YiiAsset」值;2、編輯main.php文件,在欄位「components」下方新增配置為「'yii \web\JqueryAsset' => ['js' => [],'sourcePath' => null,],」即可去掉jquery腳本。

精選幾道CTF練習,帶你學習yii2框架! 精選幾道CTF練習,帶你學習yii2框架! Feb 23, 2022 am 10:33 AM

本篇文章帶大家了解yii2框架,分享幾個CTF習題,透過它們來學習yii2框架,希望對大家有幫助。

怎麼使用YII2框架安裝Redis擴展 怎麼使用YII2框架安裝Redis擴展 May 26, 2023 pm 06:41 PM

1.需要下載yii2-redis的master分支windows版本composer下載2.解壓縮複製到vendor/yiisoft下面3.yiisoft下面extensions.php裡面增加'yiisoft/yii2-redis'=>array('name'=>'yiisoft /yii2-redis','version'=>'2.0.

yii2怎麼顯示錯誤提示 yii2怎麼顯示錯誤提示 Apr 18, 2025 pm 11:09 PM

在 Yii2 中,顯示錯誤提示有兩種主要方法。一種是使用 Yii::$app-&amp;gt;errorHandler-&amp;gt;exception(),在異常發生時自動捕獲和顯示錯誤。另一種是使用 $this-&amp;gt;addError(),在模型驗證失敗時顯示錯誤,並可以在視圖中通過 $model-&amp;gt;getErrors() 訪問。視圖中,可以用 if ($errors = $model-&amp;gt;getErrors())

伺服器中怎麼去掉index.php 伺服器中怎麼去掉index.php Dec 19, 2022 am 10:24 AM

伺服器中去掉index.php的方法:1、開啟php.ini文件,更改內容為“cgi.fix_pathinfo=1”;2、修改對應虛擬主機的設定檔;3、將“include enable-php.conf;”替換為「include enable-php-pathinfo.conf;」;4.去掉index.php,重啟lnmp即可。

https URL中怎麼去除index.php https URL中怎麼去除index.php Mar 20, 2023 pm 03:35 PM

在許多網站的 URL 中,經常會出現 index.php 的字串。儘管這個文件非常重要,但有時用戶希望將此字串從他們的 URL 中移除,以使網站結構更清晰。

tp3怎麼隱藏index.php tp3怎麼隱藏index.php Mar 03, 2023 am 10:18 AM

tp3隱藏index.php的方法:1、找到並開啟「Application/Common/Conf/config.php」檔案;2、透過修改「return array('URL_MODEL'=> 2,);」開啟REWRITE模式即可。

lnmp 怎麼隱藏index.php lnmp 怎麼隱藏index.php Oct 21, 2022 am 10:12 AM

lnmp隱藏index.php的方法:1.開啟「location ~ [^/].php」檔案;2、修改內容為「location ~ [^/].php」;3、去掉「#try_files $uri =404; 」前面的#符號;4、新增「rewrite "^/(.*)$" /index.php last;」內容;5、重啟Nginx即可。

See all articles