这是我的情景
https://x.com/remove/something/subfolder/sub.html
应该改写为
https://x.com/something/subfolder/sub
即我想删除网址部分(本例中为remove
)和文件扩展名.html
location /remove {
rewrite ^/remove(/.*)$ $1 last;
}
但它无效
更新
得到remove
部分解决了
rewrite ^/remove/(.*)$ https://x.com/$1 last;
现在只需要删除文件扩展名
答案 0 :(得分:0)
您的正则表达式正在捕获/remove
部分之后的所有内容。你需要从捕获中取出后缀。
rewrite ^/remove(/.*)\.html$ $1 permanent;
有关详细信息,请参阅this document。另外,请注意使用适当的标志。