WordPress redirects

Moving from movabletype to wordpress has involved several post moving to new locations. The redirection plugin has made adding redirects easy but only once I figured out the correct regular expressions to use. Here’s what I’ve had to use.

1) Old MT pages had .html on the permalink

Source: /(d*)/(d*)/(.*).html
Target: /$1/$2/$3/

2) A much earlier MT site had pages in an ‘archive’ directory. They also had urls with underscores instead of hyphens the wordpress pages are using, instead of spaces generated from the page title. So some archive entries had one hypen, others had four. I didn’t figure out a singe elegant regex and instead used five to do the job. Note, I couldn’t use “.*” to match as “.” would match the underscores too. The same applied to using the shortcut w as that also matches underscores.

No underscores

Source: /archives/(d*)/(d*)/([a-zA-Z0-9]*)/
Target: /$1/$2/$3/

One underscore

Source: /archives/(d*)/(d*)/([a-zA-Z0-9]*)_([a-zA-Z0-9]*)/
Target: /$1/$2/$3-$4/

Two underscores

Source: /archives/(d*)/(d*)/([a-zA-Z0-9]*)_([a-zA-Z0-9]*)_([a-zA-Z0-9]*)/
Target: /$1/$2/$3-$4-$5/

Three underscores

Source: /archives/(d*)/(d*)/([a-zA-Z0-9]*)_([a-zA-Z0-9]*)_([a-zA-Z0-9]*)_([a-zA-Z0-9]*)/
Target: /$1/$2/$3-$4-$5-$6/

Four underscores

Source: /archives/(d*)/(d*)/([a-zA-Z0-9]*)_([a-zA-Z0-9]*)_([a-zA-Z0-9]*)_([a-zA-Z0-9]*)_([a-zA-Z0-9]*)/
Target: /$1/$2/$3-$4-$5-$6-$7/


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Search this site


Free apps

  • birthday.sroot.eu – Your birthday or other celebration date based on [years on other planets] / [how many seconds/days] / [how far you’ve travelled around the sun]
  • stampulator.sroot.eu – Calculates the combination and how many 1st, 2nd, large 1st and large 2nd class Royal Mail stamps you need on large envelopes and packets

Recent posts


Archives


Categories