 <p>You can use this rule in your root .htaccess:</p> <pre><code>RewriteEngine On RewriteCond %{THE_REQUEST} \s/([^~]+?)/([^/~\s]+)/? [NC] RewriteRule ^(.+?)/([^/~]+)/?$ /$1~$2 [R=301,L,NE] RewriteRule ^([^~]+)(.+)$ /$1/$2 [R=301,L,NE] </code></pre>