.htaccess - htaccess redirect if url contains a specific word -


a site i'm working on had news articles sitting within latest news directory.

/news/latestnews/some-article-2012.html 

these have been moved in different directories depending on year of news article. 2013 within:

/news/2013/some-article-2013.html 

and 2012 in:

/news/2012/some-article-2012.html 

i can latestnews 1 of directories using:

rewriterule ^news/latestnews/(.*)$ /news/2011/$1 [r=301,l] 

but need redirect specific year directory. news articles contain year in name. some-article-2012 or some-article-2013.

any on adjusting rule check year.

thanks

=========edit=======

i've managed add rewritecond redirect correct directory having trouble appending requested file name.

so using rule

rewritecond %{request_uri} ^/news/latestnews/(.*)$ rewritecond %$1 ^(.*)2012(.*)$ rewriterule ^(.*)$ /news/2012 [r=301,l] 

this url

/news/latestnews/some-article-2012.html 

gets redirect

/news/2012  

but "some-article-2012.html" missing url.

i've tried adding $1 end of rewriterule have:

    rewriterule ^(.*)$ /news/2012$1 [r=301,l] 

but the full old url gets appended have:

/news/2012/news/latestnews/some-article-2012.html 

ok can't take full credit this, user on forum i'd posted, thought i'd share in case helps on here.

rewritecond %{request_uri} ^/news/latestnews/(.*)$ rewriterule ^news/latestnews/(.*)(201[0-9])(.*)$ /news/$2/$1$2$3 [r=301,l] 

this deal years 2010.


Comments