【问题标题】:Remove post ID from WordPress slug into separate path segment将 WordPress slug 中的帖子 ID 删除到单独的路径段中
【发布时间】:2017-09-20 11:10:22
【问题描述】:

我有一个 WordPress 网站,其中所有帖子的格式为:

http://example.com/category/12345-my-post-tile-is-here 

其中12345post_id

我希望按照以下格式进行:

http://example.com/category/12345/my-post-tile-is-here

是否可以使用.htaccess 301 重定向或使用正则表达式查找和替换的 URL 重写?

我已经尝试在 wordpress 设置中使用自定义永久链接结构,但结果不是我想要的。

我也在我的 .htaccess 文件中尝试过这个:

重定向 301 ^(.)-(.)$ /$1/$2

但是http://example.com/category/12345-my-post-tile-is-here 的结果是 http://example.com/category/12345/my/post/tile/is/here/

【问题讨论】:

  • 这应该在 WordPress 中完成,而不是 .htaccess。 (只是好奇,你为什么要做出这个微妙的改变?)
  • "12345-my-post-tile-is-here" 这是我帖子的 slug,所以我需要有没有 post_ids 的清晰 slug

标签: wordpress .htaccess redirect mod-rewrite


【解决方案1】:

使用 WordPress 永久链接支持。

您可以从 WP 仪表板Settings -> Permalinks 重写永久链接。

  1. 选择自定义结构
  2. 将值更改为/%category%/%post_id%/%postname% 并保存
  3. 您的帖子可通过http://example.com/category/postid/postname 访问

【讨论】:

  • 我已经试过了。它将我的网址转换为:myblog.com/category/12345/12345-my-post-tile-is-here。我需要通过键入 post_id 从手动插入的 slug 中删除 post_id
  • 您可以通过编辑帖子来编辑帖子标签。转到All posts -> Your post。在帖子标题下方,您应该能够编辑永久链接。它会要求你提供新的 post slug。点击确定并更新帖子。
  • 我的帖子太多了,一一发。我有 20000 或更多的帖子。这就是为什么我正在寻找一种方法来重写这些帖子的 url 或以以下格式重定向它们:example.com/category/12345/my-post-tile-is-here 而无需编辑每个帖子的 slug 或失去这些已提交给 google 的 url 的 seo 分数。
猜你喜欢
  • 2019-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-02
  • 2020-08-30
  • 1970-01-01
  • 2012-03-15
  • 1970-01-01
相关资源
最近更新 更多