>백엔드 개발 >PHP 튜토리얼 >nginx去除url中的index.php

nginx去除url中的index.php

WBOY
WBOY원래의
2016-06-13 12:01:541339검색

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으로 문의하세요.