首页 > 解决方案 > Htacces 重写转换为 nginx

问题描述

我正在尝试将以下 htaccess 重写规则转换为 nginx,但到目前为止没有运气。

htaccess 规则:

RewriteRule ^(.*)/page(.*)\.html$ /index.php?id=$2

我试图做什么(并加载页面,但找不到 id ..):

location ~ \.html$ {
    rewrite ^(|/(.*))/page\.html$ /index.php?id=$2&$args last;
    try_files $uri $uri/ /index.php?id=$uri&$args;
}   

仅使用 try 文件和基本规则,它不会加载 html 页面:

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

目前在 apache 服务器上的 url 基础是这样的:domain.tld/sub/page10.html

这会加载 domain.tld/index.php?id=10

有人可能知道我如何为这个写正确的规则吗?

提前致谢。

编辑:

通过以下重写解决:

        rewrite ^/(.*)/page(.*)\.html$ /index.php?id=$2&$args;

标签: regex.htaccessnginxurl-rewriting

解决方案


推荐阅读