I\'m trying to redirect all URLs with underscores to the same URL but with underscores replaced by hyphens.
I\'ve tried many examples online but these either provide
You can use that:
RewriteRule ^([^_]*)_([^_]*_.*)$ $1-$2 [L,NE]
RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,NE,R=301]
After @anubhava explanation. If big number of underscores can be a problem. You can use that (without variables):
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*_.*)$ $1-$2-$3-$4 [L,NE]
RewriteRule ^([^_]*)_([^_]*_.*)$ $1-$2 [L,NE]
RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,NE,R=301]