Redirect subfolder but individually redirect files within it in .htaccess

Posted on 2012-09-11
Last Modified: 2012-09-14
In my .htaccess file I have:

redirect 301 /blog                          
redirect 301 /blog/2009/06/okay-to-kiss/

I got rid of the blog section of my site so I want to redirect the main blog folder to my site's home page. I also moved some of the blog posts into other areas of my site so I want to redirect those specific blog posts to their new locations. Unfortunately, redirecting the blog folder causes problems with the specific blog post redirects. The line:

redirect 301 /blog/2009/06/okay-to-kiss/

ends up redirecting visitors to instead of

How can I fix this?

Ben Cunningham
Question by:webstuck5
    LVL 50

    Accepted Solution

    Remember that the Redirect directive's first parameter is a wildcard to match to the *beginning* of the URL.  When you put "redirect 301 /blog", any URL starting with /blog will have "/blog" replaced with your target.

    One solution is to list the most specific redirection first, thereby limiting the application of the more general redirection.

    Another solution would be to use mod_rewrite instead, which gives you much greater control.  It would be overkill in this scenario, I think.

    Author Comment

    I thought I had tried putting the general redirection after the specific reduction and it didn't work. It seems to be working now.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now