Note that there are some explanatory texts on larger screens.

plurals
  1. POhtaccess redirect if url contains a specific word
    primarykey
    data
    text
    <p>A site i'm working on had news articles sitting within a latest news directory. </p> <pre><code>/news/latestnews/some-article-2012.html </code></pre> <p>These have now been moved in to different directories depending on the year of the news article. So 2013 are now within:</p> <pre><code>/news/2013/some-article-2013.html </code></pre> <p>and 2012 are in:</p> <pre><code>/news/2012/some-article-2012.html </code></pre> <p>I can easily latestnews to one of the directories using:</p> <pre><code>RewriteRule ^news/latestnews/(.*)$ /news/2011/$1 [R=301,L] </code></pre> <p>But i need to redirect to the specific year directory. All news articles contain the year in name. So some-article-2012 or some-article-2013. </p> <p>Any help on adjusting my rule to also check the year.</p> <p>Thanks</p> <p>=========EDIT=======</p> <p>I've managed to add some RewriteCond to redirect to the correct directory but having trouble appending the requested file name.</p> <p>So using this rule</p> <pre><code>RewriteCond %{REQUEST_URI} ^/news/latestnews/(.*)$ RewriteCond %$1 ^(.*)2012(.*)$ RewriteRule ^(.*)$ /news/2012 [R=301,L] </code></pre> <p>This url</p> <pre><code>/news/latestnews/some-article-2012.html </code></pre> <p>gets redirect to </p> <pre><code>/news/2012 </code></pre> <p>but the "some-article-2012.html" is missing from the url.</p> <p>I've tried adding $1 to the end of the rewriterule so you have:</p> <pre><code> RewriteRule ^(.*)$ /news/2012$1 [R=301,L] </code></pre> <p>But the the full old url gets appended so you have:</p> <pre><code>/news/2012/news/latestnews/some-article-2012.html </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload