WordPress为通过post编辑器上传的任何图片创build附件页面,并“附加”到该post。 迁移网站后,这些附件页面不复存在,现在我们有大约1000个链接指向404的链接。
所以,我正在寻找一种方法来对任何有/ attachchement /的string进行redirect,然后将这个url重新推回到一个级别(恰好是post页面)。 例如:
http://mysite.com/2012/news/blog-post-title/attachment/image-page/ (不存在)将会去http://mysite.com/2012/news/blog-post-title/ (这确实存在)。
除了redirect一个级别之外,我还需要删除/ attachment /(在本例中为“图像页面”)之后的任何内容。
有什么build议么?
提前致谢
这听起来像是一个非常简单的重写; 除非有什么遗漏,你可以使用:
RewriteRule ^(.*)/attachment/?.*$ $1/
所以一些testing用例:
/2012/news/blog-post-title/attachment/image-page/ -> /2012/news/blog-post-title/ /2012/news/blog-post-title/attachment -> /2012/news/blog-post-title/ /2012/news/blog-post-title/attachments -> N/A
希望这可以帮助!