有关 301 重定向页面的求助

2022 年 6 月 24 日
 Superoutman

最近在迁移博客( wordpress→静态页面),迁移后页面链接会有所变化,所以打算做个 301 重定向。 下载了相关的插件,不过楼主小白不会用。。特来咨询以下的问题:

原链接 https://xxx.com/blog/%postname%.html 新链接 https://xxx.com/post/%postname%.html

如果把原链接通过 301 重定向为新的链接,postname 这个变量需要用正则写么?如果需要的话,请问该怎么写呢?

求答案,🙏

2457 次点击
所在节点    WordPress
9 条回复
InDom
2022 年 6 月 24 日
rewrite ^/blog/(.*)\.html$ /post/$1.html permanent;

也许,可以不需要插件。
Superoutman
2022 年 6 月 24 日
@InDom #1 请问这个是要写在哪里呢
PEAL
2022 年 6 月 24 日
novolunt
2022 年 6 月 24 日
页面上请求内容也需要替换
sub_filter '/blog/' '/post/';
sub_filter_once off;
sub_filter_types application/javascript text/css text/javascript application/json text/plain;
Superoutman
2022 年 6 月 24 日
@PEAL #3 Wordpress 用的是 Apache ,我是应该写在 .htaccess 里吧?
Superoutman
2022 年 6 月 24 日
@novolunt #4 好的,感谢。就是不知道把这些写在哪里,hhh
wdssmq
2022 年 6 月 24 日
这个插件目测要专业版才能有匹配模式?
wdssmq
2022 年 6 月 24 日
RewriteRule ^blog/(.*)\.html$ /post/$1.html [L,R=301]
Superoutman
2022 年 6 月 24 日
@wdssmq #8 OKOK ,好像明白了,左边写 https://xxx.com/blog/(.*)\.html$,右边写 https://xxx.com/post/$1.html ,这样对吧

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/861819

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX