首页 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  组件的配置,在进行后续的操作

企业微信截图_15976257968073.png

第二步 :

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 文件

企业微信截图_15976258044716.png

内容如下 :

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

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

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.

服务器中怎么去掉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即可。

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即可。

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模式即可。

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

在许多网站的 URL 中,经常会出现 index.php 的字符串。尽管这个文件非常重要,但有时用户希望将此字符串从他们的 URL 中去除,以使网站结构更清晰。

yii2怎么显示错误提示 yii2怎么显示错误提示 Apr 18, 2025 pm 11:09 PM

在 Yii2 中,显示错误提示有两种主要方法。一种是使用 Yii::$app->errorHandler->exception(),在异常发生时自动捕获和显示错误。另一种是使用 $this->addError(),在模型验证失败时显示错误,并可以在视图中通过 $model->getErrors() 访问。视图中,可以用 if ($errors = $model->getErrors())

See all articles