繁体   English   中英

Nginx-如何重定向从URL删除字符

[英]Nginx - How to redirect dropping a character from URL

我有这样的旧网址:

http://www.example.com/board/here-is-the-title-t1234.html

我希望将以上内容转发到这样的新网址:

http://www.example.com/forum/here-is-the-title-1234

我需要在Nginx中使用正则表达式执行以下操作:

1)删除.html

2)删除与数字一起的“ t”字符(该字符始终出现在html扩展名的最后)。

这就是我现在所拥有的:

rewrite ^/board/(.*)\.html$ http://example.com/forum/$1 permanent;

有了以上内容,我可以删除.html部分,但是很难实现(2)-删除与数字一起的字符't'。

我希望t1234在网址中可以变成1234,其中1234可以是任何数字。

以下应该工作:

rewrite ^/board/(.*)t(\d+)\.html$ http://example.com/forum/$1$2 permanent;

正则表达式演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM