Support » Fixing WordPress » How to use Redirection with regex?

  • I’m migrating my Movable Type blog to WordPress, with a different URL structure.

    What I’d ideally like is to set up 301 permanent redirect instructions for each of my posts (which are in the format /weblog/2005/12/bbc_blog_platfo.php, ie. 15 characters of title, whereas my new posts are in the WP form /2005/12/15/bbc-pilots-news-mashup-project/). But I have 360 posts and this looks like it would be a nightmare.

    So (1) could anyone advise on a mass redirection strategy that points old post URLs to the new?

    But (2), in lieu of that, please could anyone help on how to perform wildcard redirects that would at least take someone from, say, /weblog/2005/12/bbc_blog_platfo.php to the corresponding new monthly archive at /2005/12/.

    I have the Urban Giraffe Redirection plugin installed. This claims to have “full regex support”. You basically give an “old” URL and a “new URL”. Documentation says:-

    >> Both URLs can contain regular expressions (provided the regex option is checked, PHP style preg_replace). For example, if you change where your images are stored from /wp-images to /images you can add one redirection to cover it:

    So, if it is not possible to produce my easily strategy with this, how can I use regex in the old and new URLs to do something a bit less specific? I don’t have any idea how to form these patterns.


Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    You may want to read up on regular expressions in general. It’s not a simple subject, but it is very, very useful stuff to know.

    However, something that might help with your Giraffe plugin:

    That’ll redirect your visitors to the monthly archives like you state above.

    That actually sends the user to rather than replacing the variable names with the values.



    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Argh. Instead of %1/%2, use $1/$2. My bad.

    That produces a URL of

    … which produced an error of…

    Request-URI Too Large
    The requested URL’s length exceeds the capacity limit for this server.

    request failed: URI too long

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Well, I would say you didn’t describe something properly then. You don’t have /weblog in your URL anymore, do you? I thought that was sort of the point here.

    What is the old URL and what is the new URL you want to redirect it to? The full URL please.

    An example original URL is

    Whilst I would like to produce a direct redirection URL for each page, that appears to cumbersome so I would resort to redirecting that URL to – the monthly archive corresponding to the post.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Well, I don’t get it then. Double check that you have these in there:

    Old: /weblog/(.*)/(.*)/.*
    New: /$1/$2

    That should work given what you’ve told me. It should not produce an infinite URL. Did you leave the starting / off the new one?

    Hmm, it works now. I don’t remember doing anything differently, but, true enough, it is more likely to be my fault than anyone else’s.

    Thanks very much for the help. Time to look into regex, I guess… Now if only there was a way for WordPress to parse the end filename in a filename like /weblog/2005/12/audience_relati.php and bring back the most likely post with a slug beginning “audience-relati”. I think there was a plugin that searches for posts containing referred Google search terms…

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Now if only there was a way for WordPress to parse the end filename in a filename like /weblog/2005/12/audience_relati.php and bring back the most likely post with a slug beginning “audience-relati”.

    Do a test for me. Try something like this on your blog:

    See if that brings back a relevant search result. If not, try “audience+relati” and see what you get. It might be possible to convert it into a search, is what I’m thinking.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to use Redirection with regex?’ is closed to new replies.