• Due to a bunch of spammy web search sites, I’ve got a ton of broken links in my Webmaster tools that I’d like to fix.

    For some reason, these search sites don’t direct to the correct URLs because they all cut off the full URLs by adding “..” (no quotes) to the end of the URL.

    For example: This is a broken (not found) URL that I see in my Webmaster tools: http://www.doseofdigital.com/2011/10/fa..

    I’ve got about 100 of these. They all have the same syntax (site url/year/month/XX..). I tried coming up with a regex expression that would fix this, but I can’t figure it out. Basically, I want every URL that has “..” (no quotes) in it to redirect to the homepage. Only the URLs from these web search sites have the two dots, so no other legit URLs or links should be affected.

    Can someone help with this?

    Thanks,
    JMR

    http://wordpress.org/extend/plugins/redirection/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hey there,

    I’ve only put a few minute of thought into this, but it sounds like you can get what you’re looking for by using this little function in conjunction with some simple regex.

    Maybe a regex like this…

    ^/+[a-z,0-9]*\.\.

    Thread Starter jonmrich

    (@jonmrich)

    Thanks for the suggestion…that regex didn’t work

    I tried this and it seems to work. Anyone see any problems with this? Haven’t found any problems this causes anywhere else yet.

    /(.*)/(.*)/(.*)\..

    Thread Starter jonmrich

    (@jonmrich)

    Update:

    Turns out my regex didn’t work.

    The one I posted above

    /(.*)/(.*)/(.*)\..

    redirected all pages that had two dots in the URL no matter where the dots were placed. So, a link like this was incorrectly forwarded: http://www.doseofdigital.com/2009/12/monitoring-adverse-events-social-media-pharmas-biggest-brands/?utm_medium=bt.io-twitter&utm_source=twitter.com&utm_content=backtype-tweetcount

    I found that this regex worked perfect though, as it only redirected URLs that had two dots in succession.

    /(.*)/(.*)/(.*)\Q..\E

    I didn’t know the \Q...\E expression option when I suggested my first fix.

    source: \/(.*)\/(.*)\/(.*)\.\.$
    target: <base-url>/$1/$2/$3

    Would this work? The $ at the end means that these are the final characters in the string. I’ve also escaped the forward slashes — perhaps not necessary but it doesn’t hurt. Substitute your base URL for ‘<base-url>’.

    What’s the regex equivelant of ‘*’ ? (the more universal wildcard…). I want to redirect /path/to/anyfilename.php

    what would I use to regex match /path/to/*.php ?

    I found this, which works on a regex test site:

    /path/to/[^/]*\.php

    but it’s not working when I try to use it as the source URL in Redirection. Is this just incorrect?

    it should be able to match

    /path/to/file1.php
    /path/to/file2.php
    etc

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Help with Regex in Redirection’ is closed to new replies.