Blogger 中每个 archive.html 的正则表达式自定义重定向

Regex Custom Redirect in Blogger for every archive.html

我需要在 Blogger 中创建一个正则表达式自定义重定向。目的是将所有 HTML 存档重定向到其他地方。

目前我在设置/搜索首选项/自定义重定向中使用以下内容:

From:/2018_11_21_archive.html
To:/p/somewhere_else.html
Permanent:Yes

问题是这种方法需要添加每个日期,这是不可接受的。

/2016_10_21_archive.html
/2016_10_22_archive.html
/2016_10_23_archive.html
/2017_07_10_archive.html
/2017_07_10_archive.html
/2017_07_10_archive.html
/2018_11_21_archive.html
/2019_11_21_archive.html
...

到目前为止,我已经尝试过这个正则表达式但没有成功:

From:/2018_(.*)
To:/p/somewhere_else.html
Permanent:Yes

你必须转义“/”字符!前面加一个“\”即可。

这一行必须是这样的:

From:\/2018_.*

但请注意,这种方式只有 /2018_11_21_archive.html 会匹配。

如果你需要你提到的所有日期,我推荐下面这个正则表达式:

\/([12]\d{3}_(0[1-9]|1[0-2])_(0[1-9]|[12]\d|3[01]))_archive\.html

Blogger 自定义重定向不支持正则表达式。

但是我有一个解决方案给你,使用这段代码,把它放在<head>

之后
<b:if cond='data:view.isArchive and data:view.url contains "_archive"'>
<b:with value='"https://www.example.com/p/somewhere_else.html"' var='destination'>
<script>window.location.replace("<data:destination/>")</script>
<noscript><meta expr:content='"0; URL=" + data:destination' http-equiv='refresh'/></noscript>
</b:with>
</b:if>