I am having a struggle trying to get my .htaccess to remove all underscores from an url. I have a lot of old aliases in my articles and they are all with underscores. I have searched for a sollution, but couldnt find any.
example:
http://mysite.com/nl/nieuws/artikel/Article_name_underscores/999
http://mysite.com/nl/nieuws/artikel/article_name_with_underscores/999
http://mysite.com/nl/nieuws/artikel/article_name_with_More_underscores/999
What I am trying to get:
http://mysite.com/nieuws/article-name-with-underscore
http://mysite.com/nieuws/article-name-with-more-underscore
http://mysite.com/nieuws/article-name-with-even-more-underscore
As you can see I need to replace the underscore with hyphens and get it into lowercase, but the aliases are between 1 and 14 underscores. Now I've created the following rewrite rules:
RewriteRule ^nieuws/artikel/([^_]*)_([^_]*)_([^_]*)/([^_]*)$ http://mysite.com/nieuws/${lc:$1}-${lc:$2}-${lc:$3} [R=301,L]
RewriteRule ^nieuws/artikel/([^_]*)_([^_]*)_([^_]*)_([^_]*)/([^_]*)$ http://mysite.com/nieuws/${lc:$1}-${lc:$2}-${lc:$3}-${lc:$4} [R=301,L]
RewriteRule ^nieuws/artikel/([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)/([^_]*)$ http://mysite.com/nieuws/${lc:$1}-${lc:$2}-${lc:$3}-${lc:$4}-${lc:$5} [R=301,L]
With the RewriteMap on the virtualhost ofcourse
RewriteMap lc int:tolower
My question is, how do I get this dynamicly with efficient code to catch all alias between unlimited amounts of underscores?