【发布时间】:2017-09-20 11:10:22
【问题描述】:
我有一个 WordPress 网站,其中所有帖子的格式为:
http://example.com/category/12345-my-post-tile-is-here
其中12345 是post_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