从URL地址删除.php扩展名



我已经审查过以前的标题,但是我不完全理解,我无法完全执行此操作,从URL中删除PHP扩展,当我尝试像这样做时,将自动下载该文件有关删除扩展程序的其他标题我知道这些代码是错误的。

im使用nginx

请帮助我:

  • 我的意思是:www.example.com/index.php
  • 我想要:www.example.com/index

我的代码:

 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;
    }
}

在工作目录中创建.htaccess文件,然后添加此代码段。它基本上获取请求的文件名并删除" .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]

在工作目录中创建.htaccess文件,然后添加此代码段。它基本上获取请求的文件名并删除" .php"

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

创建htaccess文件并粘贴此代码。希望这对您有帮助。

重新创新 rewriteCond%{request_filename}!-f 重写 ^([ ^。] )$ 1.php [nc,l]

options lastersymlinks -multiviews

上的重新写入Engine

上的重新写入Engine

rewriteCond%{request_filename}!-f

重写 ^([ ^。] )$ 1.php [nc,l]


在.htaccess文件中写上述代码。

最新更新