regex - Apache htaccess RewriteRule to swap "+" for "-" -


at request of seo firm hired review old system, need change old urls (examples below) using "+" "-". system dynamic , none of these links stored, worried looking broken pages if change made programmatically if these articles/pages posted somewhere. want cleanly 301s in htaccess file.

examples of old urls:

domain.com/articles/charter+day+in+pa/  domain.com/things+to+do/  domain.com/search/things+to+do/  domain.com/things+to+do/brandywine+river+museum/  to:  domain.com/articles/charter-day-in-pa/  domain.com/things-to-do/  domain.com/search/things-to-do/  domain.com/things-to-do/brandywine-river-museum/ 

so, placed following in htaccess file, doesn't appear work:

rewriteengine on  rewriterule ^(.*?)\+(.*?[^\+]*?\+.*)$ $1-$2 [n] rewriterule ^(.*?)\+(.*?[^\+]*)$ $1-$2 [r=301]  rewritecond %{http_host} !^www rewriterule (.*)$ http://www.%{http_host}/$1 [r=301,l] 

any appreciated!

you can use code:

rewriteengine on  rewriterule "^([^+]*)\++([^+]*\+.*)$" /$1-$2 [l] rewriterule "^([^+]*)\+([^+]*)$" $1-$2 [l,r=301]  rewritecond %{http_host} !^www rewriterule (.*)$ http://www.%{http_host}/$1 [r=301,l] 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -