Rumah > pembangunan bahagian belakang > tutorial php > nginx去除url中的index.php

nginx去除url中的index.php

WBOY
Lepaskan: 2016-06-13 12:01:54
asal
1329 orang telah melayarinya

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>
Salin selepas log masuk


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

<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>
Salin selepas log masuk

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan