我的管理中的 Nginx URL 重写规则

标签 nginx url-rewriting

登录后端后如何重写URL?我需要将以下内容从 www.domain.com/administration/index.php、www.domain.com/administration/nextpage.php 更改为 www.domain.com/administration/index ,www.domain.com/administration/nextpage 这是我的实际配置:

server {
    server_name domain.com;
    return 301 $scheme://www.domain.com$request_uri;
}

server {
        listen 80;
        root /usr/share/nginx/www;
        index index.php;
        server_name www.domain.com;



   location / {
        rewrite ^([^\.]*)$ /$1.php;
    }

    location = / {
        rewrite ^ /index.php;
    }


    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ~ /\.ht {
            deny all;
      }
}

最佳答案

location /administration { 
    rewrite ^([^\.]*)(\.php)?$ /$1; 
}

将该 block 添加到您的配置中将从对/administration 的请求中删除 .php

关于我的管理中的 Nginx URL 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21405004/

相关文章:

nginx - nginx如何实现底层服务器宕机时出现的智能维护页面?

nginx - 防止NGINX移除端口

mod-rewrite - 将 RewriteRule 与 [L] 标志匹配后,重写不会停止

php - 网址重写不适用于 Apache

magento - 新的 Magento1.13 EE URL 重写如何工作/新的数据库表如何相互关联?

node.js - 像 php 一样从 nginx 提供 nodejs 应用程序?

macos - 在 OSX Excel 中使用 VBA 获取 HTTP 请求

同一网络中的 Docker 容器不通信

php - 使用 PHP MySQL .htaccess 和 GET 重写 URL

apache - .htaccess 将对文件名 URL 的请求重写为相应的永久链接 URL