regex - 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;
解决方案
推荐阅读
- c++ - 在 Raspberry Pi 上但不在 Linux 上运行代码时出现 Eigen 库矩阵对齐错误
- python-3.x - UserString 子类的未解析属性“数据”
- sql-server - SQL Server CPU 永久卡在 100%
- jquery - 在使用 TableTools 扩展提交 DataTable 按钮之前要求用户输入
- android - Xamarin 中已关闭应用程序的闹钟功能
- javascript - 在自定义 React 轮播中居中活动元素
- php - 将具有特定模式的行分组为一行作为 csv 文本文件
- operating-system - TRAP 指令是否仅由系统调用触发?
- powershell - 在 Powershell 中,如何从 AD 获取 passwordLastSet 作为 DateTime 而不是作为对象?
- javascript - 嵌套反应路由器组件不会在页面重新加载时加载/渲染?