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

nginx去除url中的index.php

WBOY
WBOY原创
2016-06-13 12:01:541342浏览

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>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn