Home PHP Framework YII How to hide index.php in yii2

How to hide index.php in yii2

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

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

How to hide index.php in yii2

推荐:《yii教程

yii2 url 重写 隐藏 index.php 方法

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

How to hide index.php in yii2

第二步 :

nginx   下 :

配置文件  nginx.conf 内容如下 :

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

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;

}

Copy after login

项目域名的配置整体是放在 vhost 这个目录下面,改目录下其中一个文件的内容

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

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;

        }

}

Copy after login

apche 下 : 伪静态配置
入口文件的同级目录下,放置 .htaccess 文件

How to hide index.php in yii2

内容如下 :

1

2

3

4

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

Copy after login

The above is the detailed content of How to hide index.php in yii2. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to remove jquery in yii2 How to remove jquery in yii2 Feb 17, 2023 am 09:55 AM

How to remove jquery from yii2: 1. Edit the AppAsset.php file and comment out the "yii\web\YiiAsset" value in the variable $depends; 2. Edit the main.php file and add the configuration "'yii" under the field "components" \web\JqueryAsset' => ['js' => [],'sourcePath' => null,]," to remove the jquery script.

A few selected CTF exercises will help you learn the yii2 framework! A few selected CTF exercises will help you learn the yii2 framework! Feb 23, 2022 am 10:33 AM

This article will introduce you to the yii2 framework, share a few CTF exercises, and use them to learn the yii2 framework. I hope it will be helpful to everyone.

How to install Redis extension using YII2 framework How to install Redis extension using YII2 framework May 26, 2023 pm 06:41 PM

1. You need to download the windows version of the master branch of yii2-redis with composer 2. Unzip and copy it to vendor/yiisoft 3. Add 'yiisoft/yii2-redis'=>array('name'=>'yiisoft to extensions.php under yiisoft /yii2-redis','version'=>'2.0.

How to remove index.php from the server How to remove index.php from the server Dec 19, 2022 am 10:24 AM

How to remove index.php from the server: 1. Open the php.ini file and change the content to "cgi.fix_pathinfo=1"; 2. Modify the configuration file of the corresponding virtual host; 3. Change "include enable-php.conf;" Replace with "include enable-php-pathinfo.conf;"; 4. Remove index.php and restart lnmp.

How to hide index.php in lnmp How to hide index.php in lnmp Oct 21, 2022 am 10:12 AM

How to hide index.php in lnmp: 1. Open the "location ~ [^/].php" file; 2. Modify the content to "location ~ [^/].php"; 3. Remove "#try_files $uri =404; The # symbol in front of "; 4. Add the content "rewrite "^/(.*)$" /index.php last;"; 5. Restart Nginx.

How to hide index.php in tp3 How to hide index.php in tp3 Mar 03, 2023 am 10:18 AM

How to hide index.php in tp3: 1. Find and open the "Application/Common/Conf/config.php" file; 2. Turn on REWRITE mode by modifying "return array('URL_MODEL'=> 2,);".

How to remove index.php from https URL How to remove index.php from https URL Mar 20, 2023 pm 03:35 PM

The string index.php often appears in the URLs of many websites. Although this file is very important, sometimes users want to remove this string from their URLs to make the website structure clearer.

How to display error prompts in yii2 How to display error prompts in yii2 Apr 18, 2025 pm 11:09 PM

In Yii2, there are two main ways to display error prompts. One is to use Yii::$app->errorHandler->exception() to automatically catch and display errors when an exception occurs. The other is to use $this->addError(), which displays an error when model validation fails and can be accessed in the view through $model->getErrors(). In the view, you can use if ($errors = $model->getErrors())

See all articles