V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Superoutman
V2EX  ›  WordPress

有关 301 重定向页面的求助

  •  
  •   Superoutman · 2022-06-24 09:28:06 +08:00 · 1114 次点击
    这是一个创建于 664 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    求答案,🙏

    第 1 条附言  ·  2022-06-24 10:45:21 +08:00

    我还是用插件吧,更直白一点,不然各位说的我不会应用。。 伸个手,以下两个地址,我应该如何填写? jPOGVS.png

    9 条回复    2022-06-24 11:46:53 +08:00
    InDom
        1
    InDom  
       2022-06-24 09:32:16 +08:00
    rewrite ^/blog/(.*)\.html$ /post/$1.html permanent;

    也许,可以不需要插件。
    Superoutman
        2
    Superoutman  
    OP
       2022-06-24 09:33:30 +08:00
    @InDom #1 请问这个是要写在哪里呢
    PEAL
        3
    PEAL  
       2022-06-24 10:03:08 +08:00
    novolunt
        4
    novolunt  
       2022-06-24 10:09:28 +08:00
    页面上请求内容也需要替换
    sub_filter '/blog/' '/post/';
    sub_filter_once off;
    sub_filter_types application/javascript text/css text/javascript application/json text/plain;
    Superoutman
        5
    Superoutman  
    OP
       2022-06-24 10:35:00 +08:00
    @PEAL #3 Wordpress 用的是 Apache ,我是应该写在 .htaccess 里吧?
    Superoutman
        6
    Superoutman  
    OP
       2022-06-24 10:35:53 +08:00
    @novolunt #4 好的,感谢。就是不知道把这些写在哪里,hhh
    wdssmq
        7
    wdssmq  
       2022-06-24 11:11:18 +08:00
    这个插件目测要专业版才能有匹配模式?
    wdssmq
        8
    wdssmq  
       2022-06-24 11:17:33 +08:00
    RewriteRule ^blog/(.*)\.html$ /post/$1.html [L,R=301]
    Superoutman
        9
    Superoutman  
    OP
       2022-06-24 11:46:53 +08:00
    @wdssmq #8 OKOK ,好像明白了,左边写 https://xxx.com/blog/(.*)\.html$,右边写 https://xxx.com/post/$1.html ,这样对吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5651 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:23 · PVG 11:23 · LAX 20:23 · JFK 23:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.