Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

WordPress creates an attachment page for any images uploaded through the post editor and "attached" to that post. After migrating a site, those attachment pages no longer exist, and we now have around 1000 links pointed at 404's.

So, I was looking to find a way to do a redirect for any url that has /attachement/ in it's string and then push that url back up one level (which happens to be the post page). so for instance: (which doesnt exist) will go to (which does exist).

Along with redirecting up one level, I also need to remove anything after /attachment/ (in this case the "image-page."

Any suggestions?

Thanks in advance

share|improve this question

This sounds like an extremely simple rewrite; unless there's something missing, you can use:

RewriteRule ^(.*)/attachment/?.*$ $1/

So some test cases:

/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

Hope this helps!

share|improve this answer
thanks for helping out. I added that bit of code to the .htaccess file but the redirects are not occuring. I checked to make sure that the RewriteEngine was On an functioning, and it was. How would you suggest I further debug. I work frontend mostly, so I apologize for my ignorance in this. – Rich Staats Apr 9 '12 at 21:38
You can try turning on logging and seeing what actions its taking. – Andrew M. Apr 10 '12 at 5:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.