首页 > 后端开发 > php教程 > nginx去除url中的index.php

nginx去除url中的index.php

WBOY
发布: 2016-06-13 12:01:54
原创
1329 人浏览过

nginx去掉url中的index.php

使用情境:我想输入www.abc.com/a/1后,跳转到www.abc.com/index.php/a/1

配置Nginx.conf在你的虚拟主机下添加:

<span style="font-family:SimSun; font-size:14px"> </span><span style="font-family:SimSun; font-size:14px; text-indent:2em">location / {</span><span style="font-family:SimSun; font-size:14px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> if (!-e $request_filename){</wbr></wbr></wbr></wbr></span><span style="font-family:SimSun; font-size:14px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> rewrite ^/(.*)$ /index.php/$1 last;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="font-family:SimSun; font-size:14px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> }</wbr></wbr></wbr></wbr></span><span style="font-family:SimSun; font-size:14px">}</span>
登录后复制


如果你的项目入口文件在一个子目录内,则:

<span style="font-family:SimSun; font-size:14px">location /目录/ {</span><span style="font-family:SimSun; font-size:14px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> if (!-e $request_filename){</wbr></wbr></wbr></wbr></span><span style="font-family:SimSun; font-size:14px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> rewrite ^/目录/(.*)$ /目录/index.php/$1 last;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="font-family:SimSun; font-size:14px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> <wbr style="padding:0px; margin:0px"> }</wbr></wbr></wbr></wbr></span><span style="font-family:SimSun; font-size:14px">}</span>
登录后复制

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板