nginx regex redirect replace underscore with hyphen

March 25, 2015 1.8k views
Nginx Apache

The old URL's we had, had underscores likes this:
http://mysite.org/mediaclips/commentary_bloomberg_bubble_bursts

I'd like to create a rule that redirects this to:
http://mysite.org/mediaclips/commentary-bloomberg-bubble-bursts

Note: 'commentary-bloomberg-bubble-bursts' is just an example URL string it could be anything.

I started with this but I didn't know how to substitute the underscores for hyphens:

   location /content {
     rewrite ^/content/(.*)$ /mediaclips/$1;
   }
Be the first one to answer this question.