I want to replace all hyphens inside of an URL before permanent 301 redirection. For example this: http://www.example.com/article_category/article_name to this: http://www.example.com/article-category/article-name
My .htaccess file looks like this:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ![_]
RewriteRule .? - [S=2]
RewriteRule ^/?([^_]+)_(.*)$ $1-$2 [N,L]
RewriteRule ^(.*)$ /$1 [R=301,L]
[S] flag is there to prevent the last rule to repeat every time redirect occurs, causing loop. But it seems that the last rule isn't firing, because requested URL stays the same, while I get the content from wanted page. I tried removing L flag from the third line, but it causes loop :(