【问题标题】:Redirect .htaccess file for old custom post type slug to new slug with post将旧自定义帖子类型 slug 的 .htaccess 文件重定向到带有帖子的新 slug
【发布时间】:2018-09-15 11:02:26
【问题描述】:

我有一个自定义帖子类型,带有这样的 slug:https://mysitename.org/change-wire/post-name-here。现在 CPT 有这样的蛞蝓:https://mysitename.org/changewire/post-name-here

基本上,slug 从 change-wire 更改为 changewire。我想自动重定向任何旧的更改线。我认为一个可能的解决方案是使用 RedirectMatch 规则,但是我不确定这是否正确:

我只能为一篇文章这样做,但我需要为所有文章这样做

这适用于: Redirect 301 https://mysitename.org/change-wire/post-name-here https://mysitename.org/changewire/post-name-here

如何使所有使用 change-wire/{post-name} 的帖子都可以更改 changewire/{post-name} ???

RedirectMatch 301 ???

【问题讨论】:

    标签: wordpress .htaccess url-redirection custom-post-type


    【解决方案1】:

    您可以使用正则表达式:

    RedirectMatch  301 /old-slug/(.*) /newslug/$1
    

    你的情况

    RedirectMatch  301 /change-wire/(.*) /changewire/$1
    

    这里,

    (.*) 是一个通配符,它​​匹配 /old-slug/ 之后出现的任何内容,并将其保存以在目标 URL 中使用,并且 $1 从源 URL 表达式中输出第一个通配符。

    【讨论】:

    • 这是否有效,因为我收到此页面无效
    【解决方案2】:

    试试这个:

    Options +FollowSymLinks 
    RewriteEngine On 
    RewriteRule ^(.*)/change-wire/(.*)$ $1/changewire/$2 [R,L]
    

    希望这会奏效......

    【讨论】:

      【解决方案3】:

      RedirectMatch 来做,因为它使用了正则表达式:

       RedirectMatch  301 /change-wire/(.*) /changewire/$1
      

      如果有更多像 anything-anything 这样的目录,你可以这样做:

      RedirectMatch  301 /(.+)-(.+)/(.*) /$1$2/$3
      

      注意:清除浏览器缓存,然后测试并确保没有其他规则阻止执行这些操作。

      【讨论】:

        猜你喜欢
        • 2017-01-31
        • 2021-10-17
        • 2017-06-28
        • 2015-05-06
        • 2021-08-21
        • 2018-11-23
        • 2014-11-10
        • 2017-09-19
        • 2013-09-10
        相关资源
        最近更新 更多