0

I have reviewed the previous headings, but I do not fully understand and I can not fully do this remove php extension from url, the file is automatically downloaded when I try to do it like the other headers about remove extension I know these code are wrong.

im using NGINX

Please help me with this :

  • I mean : www.example.com/index.php
  • I want : www.example.com/index

My code :

 server {

    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name 45.**.91.84;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

}
serkan
  • 3
  • 2
  • 2
    Possible duplicate of [Remove .php extension with .htaccess](https://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess) – Masivuye Cokile Sep 14 '17 at 12:31

4 Answers4

0

Create an .htaccess file in your working directory, then add this snippet of code. It basically takes the requested filename and removes the ".php"

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
0

Create an .htaccess file in your working directory, then add this snippet of code. It basically takes the requested filename and removes the ".php"

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
Exprator
  • 26,992
  • 6
  • 47
  • 59
0

Create htaccess file and paste this code. Hope this will help you.

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^.]+)$ $1.php [NC,L]

0

Options +FollowSymLinks -MultiViews

RewriteEngine on

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^.]+)$ $1.php [NC,L]


Write above code in .htaccess file.

Nikunj
  • 29
  • 8