[英]nginx rewrite subfolder and file extension from the url
This is my scenario 这是我的情况
https://x.com/remove/something/subfolder/sub.html https://x.com/remove/something/subfolder/sub.html
should be rewritten to 应该改写为
https://x.com/something/subfolder/sub https://x.com/something/subfolder/sub
ie I want to remove a URL part ( remove
in this case) and the file extension .html
即我想删除一个URL部分(在这种情况下
remove
)和文件扩展名.html
so far I've come with this 到目前为止,我已经有了这个
location /remove {
rewrite ^/remove(/.*)$ $1 last;
}
but it's not working 但它不起作用
UPDATE 更新
got remove
part solved by rewrite ^/remove/(.*)$ https://x.com/$1 last;
通过
rewrite ^/remove/(.*)$ https://x.com/$1 last;
解决了remove
部分rewrite ^/remove/(.*)$ https://x.com/$1 last;
now just need the file extension removal only 现在只需要删除文件扩展名
Your regular expression is capturing everything after the /remove
part. 您的正则表达式将捕获
/remove
部分之后的所有内容。 You need to take the suffix out of the capture. 您需要删除后缀。
rewrite ^/remove(/.*)\.html$ $1 permanent;
See this document for details. 有关详细信息,请参见此文档 。 Also, note use of the appropriate flag.
另外,请注意使用适当的标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.