0

I know this should be the easiest thing in the world, but I just can't get my head around rewriting and I have to do it so infrequently that I end up trawling Google for hours....

I'm consolidating two wordpress blogs into one new blog at a different URL. Alas, they both have different permalink structures.

The best thing I can come up with, is to redirect the less popular of the two to the search function of the new one - however I've fallen at the last hurdle: I need to replace all instances of hyphens in the URL to plus symbols.

What I have is this:

RedirectMatch permanent /[0-9]{4}/[0-9]{2}/([a-z0-9\-]+) http://www.mynewblogurl.com/blog/?s=$1

Which will give me: http://www.mynewblogurl.com/blog/?s=the-title-of-the-blog

I just need to find a way of changing those hyphens into plus symbols.

Khaled
  • 36,533
  • 8
  • 72
  • 99
Gary
  • 103
  • 1
  • 3
  • possible duplicate of [Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?](http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-rules-but-were-afraid-to-as) – EEAA Apr 12 '12 at 12:26

1 Answers1

1

You're trying to do a search/replace using regex in rewrite rules, which isn't possible. You can see some potential workarounds in this previous question

Andre Lackmann
  • 426
  • 2
  • 6
  • Ahh. I see. Thanks for letting me know, but I'd already seen the question you linked to and couldn't get it to solve my problem. – Gary Apr 12 '12 at 12:40
  • 2
    If you know the maximum length of the blog title, you could create enough rules to cover all examples. A cleaner way would be to rewrite to a server-side script (say PHP) that takes the URI, rewrites it and does a redirect (effectively a rewrite in code). This will be slower, but if it's important to you to be perfect, then could be the answer. If the problem is just cosmetic, it might be easier to just live with it. – Andre Lackmann Apr 12 '12 at 12:44
  • Rewrite to a PHP script gets my vote. I've seen this done with RewriteRule chaining `[N]` and it caused an infinite loop in Apache's rewrite engine when certain requests came through. The manual says that `[N]` is dangerous. – Ladadadada Apr 12 '12 at 12:48
  • Sounds like this is the way to go, yes... So I have the redirect point to my serverside script, presumably passing the old URL as a query string. I'll give that a go. Cheers. – Gary Apr 12 '12 at 13:29