regex - htaccess redirect /foldername/page_name to /page-name -


i have issue: replaced old website (no cms) new website (and wordpress cms). lot of people still try access website old url's. want redirect them right page.

for example: previous url was: http://domain.com/foldername/page_name

on new website same page located @ http://domain.com/page-name

note #1: underscore has been replaced dash

note #2: pages may include more underscores. example: http://domain.com/foldername/an_other_page_name

note #3: since use wordpress cms, there code in .htaccess file.

# begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule>  # end wordpress 

since i'm not htaccess of hope has solution, since i'm losing visitors because can't find right page.

just below rewritebase line can use recursive rule:

rewriterule "^(foldername)/([^_]*)_+([^_]*_.*)$" /$1/$2-$3 [n] rewriterule "^(foldername)/([^_]*)_([^_]*)$" /$2-$3 [l,r=301] 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -