nginx regex redirect replace underscore with hyphen

March 25, 2015 1.4k views
Nginx Apache

The old URL's we had, had underscores likes this:

I'd like to create a rule that redirects this to:

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.