Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

http://mysite.com/2012/news/blog-post-title/attachment/image-page/ (which doesnt exist) will go to http://mysite.com/2012/news/blog-post-title/ (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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.