Home > PHP Framework > YII > yii method to hide index.php

yii method to hide index.php

藏色散人
Release: 2020-11-30 10:51:59
Original
2222 people have browsed it

yii method to hide index.php: first add urlManager in the configuration file main.php; then create a new .htaccess file in the same directory as index.php; finally configure nginx.conf and vhosts.conf .

yii method to hide index.php

The operating environment of this tutorial: linux5.9.8 system, PHP5.6 version. This method is suitable for all brands of computers.

Recommended: "PHP Video Tutorial"

Yii Hide index.php (Apache nginx)

1. In configuration Add

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

2.1 and Apache configuration

to the file main.php. At the same time, create a new .htaccess file in the same directory as index.php

#表示开启重写引擎
RewriteEngine on
#请求的文件或路径是不存在的,如果文件或路径存在将返回已经存在的文件或路径
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Copy after login

.htaccess file explanation

In summary, the htaccess file is a configuration file in the Apache server, which is responsible for the configuration of web pages in related directories.

Through htaccess files, we can help us achieve: web page 301 redirection, custom 404 error page, change file extension, allow/block access to specific users or directories, prohibit directory lists, configure default documents, etc. Function.

2.2, nginx configuration

① nginx.conf configuration

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;
        #你的项目根目录
        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(.*)$  {
            #你的项目根目录
            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;
}
Copy after login

② vhosts.conf configuration

server {
        listen       80;
        #你的虚拟主机名
        server_name  www.luluqi.com ;
        #虚拟主机根目录
        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;
        }
        
}
Copy after login

For more programming related knowledge, please visit:Introduction to Programming! !

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

Related labels:
yii
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template