views:

29

answers:

3

Hi, I got a question.

How do I 301 redirect, for exemple: a subdirectory /Blog/ to /blog/ with .htaccess?

Thanks

A: 

The way that immediately comes to mind:

RewriteEngine on
RewriteBase /path/to/your/web/app
RewriteRule ^Blog$ blog [R=301,L]
RewriteRule ^Blog/(.*)$ blog/$1 [R=301,L]

There are probably much better ways than mod_rewrite, and I'm not 100% sure that the external redirects will work as they should -- you may need the full URL -- but there you go.

Andrew
+2  A: 

Redirect 301 /Blog /blog

Or use something like http://www.htaccessredirect.net/index.php

Sam Plus Plus
A: 

This is the simplest .htaccess solution, place it in /.htaccess:

Redirect 301 /Blog /blog

But it's really limited. If you want to catch every possible CaSe-wise misspelling, and also forward any other path info (such as /Blog/foo/bar.html), use this instead:

RedirectMatch 301 ^/[Bb][Ll][Oo][Gg](?<!blog)(/.*)?$ /blog$1

For more options, there are full .htaccess generators available.

Or you can use ModRewrite-based rules for maximum flexibility, but it's probably overkill.

Jay Dansand
Your second example will also match `/blog` at any position.
Gumbo
Very correct - I rushed to hit the Add Answer too quickly. Thanks for pointing it out! The REGEX is fixed now.
Jay Dansand
Yes indeed this one is way better althouth there alway the famous:"Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. "
Necronet