301 redirect .htaccess

301 redirect .htaccess

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

Solutions/Answers:

Solution 1:

Redirect 301 /Blog /blog

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

Solution 2:

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.

Solution 3:

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.

References

Related:  htaccess file somehow being cached?