Heim > Backend-Entwicklung > PHP-Tutorial > nginx去除url中的index.php

nginx去除url中的index.php

WBOY
Freigeben: 2016-06-13 12:01:54
Original
1329 Leute haben es durchsucht

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>
Nach dem Login kopieren


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

<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>
Nach dem Login kopieren

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage