.htaccess Redirect Subdomain and Directory also Force WWW

.htaccess redirect the best tool for re-directions any pages website, domain, subdomain or a Directory.

My friend came across a situation like http://www.mydomain.com/blog/ which he moved to the sub domain http://blog.mydomain.com as all of work need to be done on a live domain. so .htaccess redirect Subdomain to Directory easy guide.

URL Friendly Structure

.As every one is aware about the 301 redirect, which means the spiders will follow it and know, What to read and what not

Just follow few easy steps to set up that redirect in the .htaccess file in the root of mydomain.com, meaning you can completely get rid of the /blog/ directory, which is great cause cluttered folders don’t make anyone happy.

htaccess redirect steps

As we were in there we added a few lines to force the www to the rest of the domain. This helps ensure you don’t get scolded by Google (via page rank) for having duplicate content on example.com/whatever-page.html and www.mydomain.com/anyone-page.html

Options -Indexes +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com$1 [L,R=301]

RedirectMatch 301 ^/blog/(.*)$ http://blog.mydomain.com/$1

Cheers, every one love it when things work quickly and easily!

This works with any blog, or heck even forums: WordPress, Movable Type, Expression Engine, Geek Log, Simple Machines Forums, vBulletin…you name it! The reason is: because it doesn’t care if you have a hand coded manually updated blog all the .htaccess file sees is that someone is trying to access www.mydomain.com/blog/this-post/ and it redirects to blog.mydomain.com/this-post/.

ITRC, offering Services like Web Hosting Pakistan, e services like Web Design and Web Development with Internet Marketing in Pakistan,   So get going, move stuff around…keep reading Web Hosting Blog

Comments are closed.