Adding redirects with a regex using redirection plugin

Our second book is called A Leaf in a Gale by Susan Capindale. The book printing has the URL http://www.lifesignpress.com/capindale/ though we haven’t got that site ready yet until she produces the next book. For the moment we’re redirecting that to the first book URL i.e.  http://www.lifesignpress.com/aleafinagale/

To do this we’ve used the Redirection plugin and enabled it on the main site i.e. lifesignpress.com (not network enabled). Get this plugin here – http://wordpress.org/extend/plugins/redirection/

Simply upload the redirection directory contents to your /wp-content/plugins subdirectory via FTP and then enable the plugin (just the main site) and then go into the Settings for the plugin.

We initially added redirects from URL such as  /capindale and /capindale/ and to the URL of /aleafinagale/ but then I realised that we need to look at CAPital URLs.

OK so we need a regex only the redirection plugin doesn’t allow you to add regex options to ignore case. It just takes the string you supply and then puts that inside the regex (in it code it uses preg_match() and similar and uses the ‘@’ symbol as the regex delimiter) thus you cannot provide options that are outside of that regex. Thus I was doomed to create the following regex string for it to wrap inside the regex delimiters,

^/+(C|c)(A|a)(P|p)(I|i)(N|n)(D|d)(A|a)(L|l)(E|e)/*.*

and redirect that to the URL of /aleafinagale/

What does that regex match ?

  • The ^ means start
  • the /+ means one or more slashes
  • the (C|c)(A|a) etc means upper or lower case letter at that position for my word which I have spelt out
  • the /* after your letter sequence at the end means followed by none or more /
  • the .* at the end means followed by anything

so this will match /CAPINDALE//// or //capindale and anything in between that.  URLs are case sensitive though you would not usually think this with the way people write them in advertising (sure domain names are not sensitive but the resource on the host is case sensitive) but with Permalinks enabled then WordPress ends up being case sensitive and you could end up with 404 page not found errors.

Remember to check the [*] Regex flag.

 

This entry was posted in Wordpress. Bookmark the permalink.

Comments are closed.