总结
豆包 AI 助手文章总结
首页 > php框架 > YII > 正文

yii 隐藏index.php的方法

藏色散人
发布: 2020-11-26 09:27:17
原创
2424人浏览过
yii隐藏index.php的方法:首先在配置文件main.php中添加urlManager;然后在index.php同级目录下新建.htaccess文件;最后配置nginx.conf和vhosts.conf即可。

yii 隐藏index.php的方法

本教程操作环境:linux5.9.8系统、PHP5.6版,该方法适用于所有品牌电脑。

推荐:《PHP视频教程

Yii 隐藏 index.php(Apache + nginx)

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

立即学习PHP免费学习笔记(深入)”;

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

2.1、Apache 配置

同时还要在index.php同级目录下新建.htaccess文件

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

.htaccess文件解释

概述来说,htaccess文件是Apache服务器中的一个配置文件,它负责相关目录下的网页配置。 

通过htaccess文件,可以帮我们实现:网页301重定向、自定义404错误页面、改变文件扩展名、 允许/阻止特定的用户或者目录的访问、禁止目录列表、配置默认文档等功能。

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;
        #你的项目根目录
        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;
}
登录后复制

② vhosts.conf 配置

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;
        }
        
}
登录后复制

更多编程相关知识,请访问:编程入门!!

以上就是yii 隐藏index.php的方法的详细内容,更多请关注php中文网其它相关文章!

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号