You need to use htaccess files in order to do this, one way is to use mod_rewrite, here is the code:
CODE
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/blog/(.*)$ http://blog.example.com/$1
So whenever someone will go to example.com/blog/ it will redirect him/it to your subdomain blog.example.com with a permanent redirect code 301, which is good for lets say spiders and other web robots.
More about it on this blog entry I found through google:
http://blog.ninedays.org/2008/03/11/htacce...-and-force-www/Another way would be doing the same thing with PHP, if you're using index.php you just need to check $_SERVER superglobal HTTP_HOST as I remember if it's not blog.example.com but only example.com also redirect with a 301 code using header() + Location, it will do the same, but I believe using htaccess method is much better, as I think it will also redirect example.com/blog/images/Logo.jpg to blog.example.com/images/Logo.jpg where using PHP would only redirect dynamic pages.

Comment/Reply (w/o sign-up)