nginx去掉index html改为index php

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                apache下只要在全局配置文件中设置了缺省首页index.html就能实现直接到达index.php,但是nginx目前默认情况下只能到达index.html而不能访问到index.php,初期接触NGINX的er可能会觉得很困扰,下面来介绍一下这问题怎么借助URL重定位rewrite技术,才能实现缺省index.html时,跳转到index.php页面进行访问。
    具体情况请看以下代码:
   
01. location / {
02.  
03.  
04. root   /var/www/androidren.com/;
05. index  index.html index.htm;
06.  
07. if (-f $request_filename/index.php){
08. rewrite (.*) $1/index.php;
09. }
10. if (!-f $request_filename){
11. rewrite (.*) /index.php;
12. }
13.  
14.  
15. }

预览效果:(可以看到不仅能正确访问,还能实现参数传递)
\


当然也可以利用更简单的方法,创建一个index.html 然后利用JS重定位到index.php!           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/gfdhjf/article/details/84039281
今日推荐