问题描述
几年前,当我重新创建网站时,一些旧的散乱页面以旧格式保留。因此,我在htaccess中编写了重定向,以将其发送到新页面。问题是旧的url在我不再使用的main变量的末尾添加了一个字符。我将如何删除该字符,它是“ r”还是“ p”?这是我的一个重定向示例。
RedirectMatch 301 /season-stats-regular-season-(.*)\.html https://www.lakerstats.com/season-stats/?seasonid=$1
因此它重定向页面:
https://www.lakerstats.com/season-stats-regular-season-5960r.html
收件人:
https://www.lakerstats.com/season-stats/?seasonid=5960r
问题是,我需要删除“ r”,以便处理:
https://www.lakerstats.com/season-stats/?seasonid=5960
我该怎么写才能在重定向代码中删除“ r”?就像我说的那样,它也可以是“ p”。
谢谢!
解决方法
您可以使用以下规则:
RedirectMatch 301 ^/season-stats-regular-season-(.+)r\.html$ /season-stats/?seasonid=$1
在测试此更改之前,请确保清除浏览器缓存。