remove php file extension with nginx/php-fpm

对着背影说爱祢 提交于 2021-02-10 19:43:36

问题


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

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

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


回答1:


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;

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/



来源:https://stackoverflow.com/questions/8970674/remove-php-file-extension-with-nginx-php-fpm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!