2

我需要在 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
4

2 回答 2

4

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>
于 2019-11-24T11:52:16.000 回答
0

您必须转义“/”字符!只需在前面插入一个“\”。

这一行必须是这样的:

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
于 2019-11-24T02:19:35.200 回答