您的位置:首页 > 运维架构 > Nginx

nginx去掉index.html改为index.php

2014-12-22 22:03 351 查看
apache下只要在全局配置文件中设置了缺省首页index.html就能实现直接到达index.php,但是nginx目前默认情况下只能到达index.html而不能访问到index.php,初期接触NGINX的er可能会觉得很困扰,下面来介绍一下这问题怎么借助URL重定位rewrite技术,才能实现缺省index.html时,跳转到index.php页面进行访问。
    具体情况请看以下代码:
   

view
source

print?

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!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: