当前位置:首页 > 服务器技术 > nginx

nginx怎么去掉.php后缀

nginx去掉“.php”的方法:首先找到并打开nginx相应文件;然后修改代码为“location / {try_files $uri $uri/ $uri.php?$args;}”;最后保存该文件即可。

nginx怎么去掉.php后缀 - 文章图片

nginx rewrite 隐藏.php后缀

我想实现http://xxx.com/post/abc.php隐藏后缀的效果,即:http://xxx.com/post/abc,网上搜了一大堆都只是隐藏index.php重定向到入口文件,这个谁不会啊,但这不是我想要的。然后有的说nginx不行,只能用apache,然而我只轻轻的改了改,一切就是那么的如丝搬顺滑,正是我要的效果!

其实很简单,一行代码的事情

location / {
    try_files $uri $uri/ $uri.php?$args;
}

现在下面两组url的访问效果是一样的

before:
http://abc.com/login.php
http://abc.com/register.php
http://abc.com/blog/post.php
http://abc.com/xxx/xxx/anything.php
after:
http://abc.com/login
http://abc.com/register
http://abc.com/blog/post
http://abc.com/xxx/xxx/anything

推荐:《PHP教程》

以上就是nginx怎么去掉.php后缀的详细内容。


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!