yii2 隐藏index.php,yii2 url重写并隐藏index.php方法

news/2024/7/3 10:49:36

第一步 : 不管是 apache 还是 nginx ,想要隐藏 Index.php 文件,需要打开 urlManager 组件的配置,在进行后续的操作[‘components" => [ "urlManager" => [ "enablePrettyUrl" => true,//开启美化URL "showScriptName" => false,//是否显示脚本名称:index.php,同时应该配置 Web 服务 "enableStrictParsing" => false,//是否开启严格解析 //"suffix" => ".html",//生成带 .html 后缀的 URL "rules" => [ ], ],],]

第二步 :

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

内容如下 :RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持网页设计。


http://www.niftyadmin.cn/n/4002411.html

相关文章

php .htaccess文件不生效,.htaccess文件怎么不管用啊?呜呜呜~

各位大神早上好,我在使用.htaccess文件重写url的时候发现文件怎么也不起作用,下面是我的一些操作过程,请大神帮我看看哪里出了错。谢谢!对httpd.conf做一下修改:1.去掉"LoadModule Rewrite_module modules/mod_Re…

idea编辑器激活码

激活方式:License Server1、将地址 http://active.chinapyg.com/ 或者 http://idea.toocruel.net 任意一个复制到License Server中 2、IntelliJ IDEA 注册码 IntelliJ IDEA 注册码:G91XMO9AVI-eyJsaWNlbnNlSWQiOiJHOTFYTU85QVZJIiwibGljZW5zZWVOYW1lIjoi…

php将excel导入mysql,PHP实现将EXCEL文件导入到MYSQL

最近因项目需求,要实现将excel文件通过php页面导入mysql数据库中。在网上搜了很多这方面的资料,发现都是将excel文件另存为csv文件,然后从csv文件导入。这里介绍一个直接将excel文件导入mysql的例子。我花了一晚上的时间测试,无论…

face recognition[Euclidean-distance-based loss][Center Face]

本文来自《A Discriminative Feature Learning Approach for Deep Face Recognition》,时间线为2016年。采用的loss是Center loss。 0 引言 通常使用CNN进行特征学习和标签预测的架构,都是将输入数据映射到深度特征(最后一层隐藏层的输出&…

对于json文件的读写操作

为什么80%的码农都做不了架构师?>>> 对json文件的读操作 返回的一个列表,里面是多个字典 def read_json(self,jsonname):with open(r"./{}.json".format(jsonname),"r") as json_f:text_list json_f.read()lists json…

php和python的多线程,python3多线程

多线程类似于同时执行多个不同程序,多线程运行有如下优点:(推荐学习:web前端视频教程)使用线程可以把占据长时间的程序中的任务放到后台去处理。用户界面可以更加吸引人,比如用户点击了一个按钮去触发某些事件的处理,可…

深入探索WebSockets

WebSockets简介 在2008年中期,开发人员Michael Carter和Ian Hickson特别敏锐地感受到Comet在实施任何真正强大的东西时所带来的痛苦和局限。 通过在IRC和W3C邮件列表上的合作,他们制定了一项计划,在网络上引入现代实时双向通信的新标准&#…

java 焦点转移,java焦点的获取和转移

方法一://使用动作监听实现焦点转移package za;import java.applet.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class Text extends Applet implements ActionListener {private static final long seria…