I need help with one redirect, unfortunately I don't have idea how to write this for Wordpress. Should be .htaccess redirect or function in functions.php? Noob I am, so please help :)

OK, I have post, for example mysite.com/post1/ now, i have plugin that adding image to post as mysite.com/post1/thumb_image1.jpg but for some reason this plugin also adding page mysite.com/post1/mysite.com/post1/image1.jpgTHUMB that does not exist, so giving me 404 I need to sort. Now I can not remove this plugin, but how can I say to google not to crawl link mysite.com/post1/mysite.com/post1thumb_image1.jpgTHUMB and if it does (or someone accidentally find it) than do 301 on that link and redirect it to parent post, so example mysite.com/post1/

so something like Redirect 301 mysite.com/ABC/**.jpgTHUMB to mysite/com?ABC There are a lot of posts so this should apply to any post in my website. I think that above is possible through some kind of redirect, but I read like 60 pages and tried so many options and nothing works. now got headache of all this code, so please help.

1 Answer 1


You should solve this at the plugin level. While this rewrite rule …

RewriteRule (.*)/?mysite.com/(.*) /$1/$2 [L,R=301]
RewriteRule ^(.*)THUMB /$1 [L,R=301]

… does what you are asking for, it is just cosmetic. Find the code that creates the wrong URL and fix that. Give the plugin author feedback; I’m sure s/he wants to know about that issue.

  • Hi toscho, thank you for comment and help. yes, i need just a quick fix before i find a way to modify plugin. Your example didn't work for me :( is there a rewrite that will return any URL containing /THUMB to parent post? So if I have mysite.com/post57/THUMB45/875/this.jpg it will redirect it to mysite.com/post57/
    – Dean
    Commented Aug 9, 2012 at 8:46
  • @Dean See my update.
    – fuxia
    Commented Aug 9, 2012 at 11:29
  • Hi toscho, thank a lot - that worked perfectly! Thank you for UPDATE your code is brilliant. But when checking links I discover another issue - this time links start with "?link=" instead of "THUMB" - can i use code like: RewriteRule (.*)/?mysite.com/(.*) /$1/$2 [L,R=301] RewriteRule ^(.*)?link= /$1 [L,R=301]
    – Dean
    Commented Aug 10, 2012 at 0:22
  • Please edit your question: Add a link to the plugin, so we can look at its source code.
    – fuxia
    Commented Aug 10, 2012 at 2:06
  • Hi toscho, thank you a lot for your offers, but this plugin is paid so i can not share or distribute code. and there is no response from author. i'll have to patch this few issues for now :( thank for your help :)
    – Dean
    Commented Aug 10, 2012 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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