Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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