WordPress.org

Ready to get started?Download WordPress

Forums

Redirection
Help with Regex in Redirection (8 posts)

  1. jonmrich
    Member
    Posted 2 years ago #

    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/

  2. @danomak
    Member
    Posted 2 years ago #

    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.

  3. openmtl
    Member
    Posted 2 years ago #

    Maybe a regex like this...

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

  4. jonmrich
    Member
    Posted 2 years ago #

    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.

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

  5. jonmrich
    Member
    Posted 2 years ago #

    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.

  6. stevemagruder
    Member
    Posted 2 years ago #

    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>'.

  7. Gabe462
    Member
    Posted 2 years ago #

    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 ?

  8. Gabe462
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic