使用 nginx/php-fpm 删除 php 文件扩展名 [英] remove php file extension with nginx/php-fpm

查看:75
本文介绍了使用 nginx/php-fpm 删除 php 文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许有人可以帮我解决这个问题.我想删除 php 扩展.(我想在 nginx 中使用grapaperch).这是 apache 重写规则:

maybe someone can help me with this problem. I want to remove the php extension. (i want to use grabaperch with nginx). This is the apache rewrite rule:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ $1.php [L] 

Redirect 301 /portrait /portrait/zu-meiner-person.php

我在 ubuntu 11.04 上使用 nginx 0.8.54 和 php5-fpm.

I use nginx 0.8.54 with php5-fpm on ubuntu 11.04.

像这样/folder/file.php 这样的 URL 应该像这样/folder/file/.像这样的 URL/folder/应该显示 index.php

URLs like this /folder/file.php should look like this /folder/file/ . URLs like this /folder/ should display the index.php

推荐答案

经过大量的反复试验,我终于找到了一个可行的解决方案.检查下面

After a lot of trial and error, i managed to end up to a working solution.Check below

try_files $uri $uri.php;
rewrite ^(.*)$ $uri.php;

不过,如果有人知道如何在 uri 的末尾添加/",那就太好了.将 example.com/products.php 改为 example.com/products/

Would be nice though if someone know how to add '/' in the end of the uri. Instead of example.com/products.php to become example.com/products/

这篇关于使用 nginx/php-fpm 删除 php 文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆