我跑了一些自定义的PHP页面的WordPress的网站。
如果url不例如延长(http://example.com/test
)结束了,我想Nginx的尝试首先改写为http://example.com/test.php
,如果test.php
不存在,它改写为http://example.com/test/
。
我该如何做到这一点?
我跑了一些自定义的PHP页面的WordPress的网站。
如果url不例如延长(http://example.com/test
)结束了,我想Nginx的尝试首先改写为http://example.com/test.php
,如果test.php
不存在,它改写为http://example.com/test/
。
我该如何做到这一点?
使用try try_files:
http://wiki.nginx.org/HttpCoreModule#try_files
例如(未测试):
try_files $uri $uri/ /test.php
尝试此,它会尝试实际URI然后用PHP
try_files $uri $uri.php $uri/
请注意,这是很危险的! Try_files *字面意思*表示尝试在磁盘上的文件。在这里没有位置重新评估,所以会发生的是nginx将以文本形式提供文字.php文件,而不会将其传递给PHP。只有try_files的最后一个参数才会导致内部重定向以及位置重新评估。 –
使用该方法,'http:// example.com/test'只重写为'http:// example.com/test /'。如果该文件实际上是'test.php',它返回一个404 – waylaidwanderer