.htaccess - Using regular expression in htaccess for 301 redirects -


i have wordpress blog redirecting blog posts old blog new blog in format below:

the old blog called 'news' , new blog called 'blog' - both exist on same domain in subdirectory indicated below.

old 'news' blog structure

http://www.site.com/news/new-android-os-3431 

new 'blog' blog structure

http://www.site.com/blog/new-android-os 

essentially redirect needs 2 things:-

  1. redirect 'blog' directory
  2. retain post name in same structure remove last set of numbers @ end of url

i have around 900+ posts need setup redirects - know manually add each 1 in take time. indicate if using regular expression directly within htaccess file minimise process.

my htaccess looks this:

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

end wordpress

using mod_alias:

redirectmatch 301 ^/news/(.+?)(-[0-9]+)?$ /blog/$1 

or using mod_rewrite:

rewriteengine on rewriterule ^news/(.+?)(-[0-9]+)?$ /blog/$1 [l,r=301] 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -