• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Redirect subfolder but individually redirect files within it in .htaccess

In my .htaccess file I have:

redirect 301 /blog                                    http://www.romancestuck.com/
redirect 301 /blog/2009/06/okay-to-kiss/ http://www.romancestuck.com/articles/news/okay-to-kiss.htm

I got rid of the blog section of my http://www.RomanceStuck.com 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/ http://www.romancestuck.com/articles/news/okay-to-kiss.htm

ends up redirecting visitors to http://www.romancestuck.com/2009/06/okay-to-kiss/ instead of http://www.romancestuck.com/articles/news/okay-to-kiss.htm

How can I fix this?

Thanks!
Ben Cunningham
0
webstuck5
Asked:
webstuck5
1 Solution
 
Steve BinkCommented:
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.
0
 
webstuck5Author Commented:
I thought I had tried putting the general redirection after the specific reduction and it didn't work. It seems to be working now.

Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now