子文件夹根目录中的默认重定向未重定向到index.php

时间:2019-05-11 13:06:52

标签: nginx redirect

在根目录中,任何重定向到localhost/的地址都只是重定向到index.php,但是如果您进入localhost/phone子目录,也将有一个index.php页面,并且在键入{ {1}}您不会重定向到index.php页面。不知道为什么。这是我的服务器配置。

localhost/phone/

我试图指向目录并为index.php添加默认值,并且它可以正常工作,但是现在server { listen 80; listen [::]:80 default_server; server_name localhost; charset UTF-8; index index.html index.php; location / { root xyz; proxy_set_header Connection ""; if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; } try_files $uri $uri/ $uri.html $uri.php?$args; rewrite ^/(.*)/$ /$1 permanent; location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|webp)$ { expires 365d; } } 中的所有url都显示为空白。

/phone/

“显示空白”表示根据错误日志显示404错误

  

2019/05/08 23:40:58 [错误] 26240#14076:* 1 CreateFile()   “ C:\ xyz \ nginx / xyz / phone / index”失败(2:系统找不到   指定的文件),客户端::: 1,服务器:本地主机,请求:“ GET   / phone / index HTTP / 1.1“,主机:” localhost“

现在index.php显示404错误,我在做什么错?即使文件在那里

1 个答案:

答案 0 :(得分:1)

如果要避免所有URI都尾随/,但仍测试index.htmlindex.php,则应避免使用index伪指令和{{ 1}}字词和$uri/指令。

一种方法是使用命名位置来测试PHP文件。此位置需要您的try_files配置。

例如:

fastcgi
相关问题