So I've recently moved a blog from Wordpress to ExpressionEngine. Everything transferred over great (thanks to DataGrab!!).

Now the one problem I'm having is in my attempt to redirect traffic from the old blog to the new one. I've implemented an HTACCESS like so:

RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.new_ee_site.com/blog/view/$4 [R=301,NC,L]

To redirect the old blog posts to their new counterparts on the EE install.

Here's the problem: This works for post with short titles just fine, the problem is some post titles are greater than 75 characters (the default EE url_title limit). So the post with titles name greater than 75 aren't translating over (since, when importing, the blog titles for the EE blog got trimmed to 75 characters).

Is there a way to somehow truncate incoming URLs, if they match the format /blog/view/..blog-title.., to truncate / trim the blog-title portion to 75 characters so these links go to the right place?


3 Answers 3


Using the info from the link provided by AllinOne https://stackoverflow.com/questions/1649435/regular-expression-to-limit-number-of-characters-to-10 you should be able to solve this. The information is relevant to your problem as it lets you match a number of characters in a given string.


RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*){1,75}$ http://www.new_ee_site.com/blog/view/$4 [R=301,NC,L]

I'm not sure if you will need to change the (.*) to something like ([a-z][A-Z][0-9]){1,75} but effectively you are saying grab the first 75 characters of the last segment of the url.

I've had a quick play around and this might be better. It depends on what characters are in your WP URLs. This one should match upper and lower case characters, hyphens, and underscores. It also assumes that the first 3 segments of your URLs are digits (are they dates?).



Try this regex instead

  • I tried a simplified version of your regex just to see if I could get the redirect to work, and it doesn't work at all. I tried RewriteRule ^([0-9]+\/){3}/([a-zA-Z0-9\-\_]+)$ http://www. new_ee_site.com/blog/view/ [R=301,NC,L] just to get a generic redirect working with it before I started to fine-tune, and nothing? Thanks for the suggestion though...
    – shparkison
    Aug 8, 2014 at 15:04

Thinking on my feet here.

I don't think you can do this via htaccess so what I would do is ensure that these urls end up at a special template (you might do it on a 404 page but I'm not sure of the SEO implications there).

Then on that special template I would look for the presence of 'blog' in segment_1 then grab segment_3, truncate it (with PHP or a plugin) and then feed the result into either a redirect or directly into a channel:entries tag.

You should also respond with a 301 http code so the referring URL can make any changes needed (Google etc will like this!)

I've used this technique with 404 pages before when moving a site from one platform to another or after a big change in url structure and it's been quite successful.

This feels really clumsy and there may well be a more elegant way to do it. Like I said, thinking on my feet over morning coffee!

  • Yes. I like this approach and use it myself. We do it a little differently tho. The 404 page looks to see if it's the sort of URL we want to preserve ('blog' in segment_1, in your example) if it is we run through a translation table of all the urls we want to prevent from breaking. This gives us the ability to preserve urls that don't follow a specific rule... maybe the url was changed after import to the new site for example. Then we return either 404 or 301 depending if we got a match.
    – AllInOne
    Aug 8, 2014 at 16:32

Ok, thanks to both @foamcow and @AllInOne I was able to weed out the solution.

So here is what works:

RewriteBase /
RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/([a-zA-Z0-9\-/_]{0,75})(.*)$ http://www. new_ee_site.com/blog/view/$4 [R=301,NC,L]

Basically, I used


to match the 75 characters I was after, then I had to add the


Because otherwise it didn't match any URLs that had a title greater than 75, so i had to take that into account. Now the $4 variable contains the first 75 characters of the URL, and the other variables aren't used, but 1-3 are the date, and 5 is the part that gets trimmed off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.