How to add url redirect from subfolder to subdomain?

At any stage of development a developer faces this situation. I am just trying to provide you guys a way to add url redirect from sub-folder to sub-domain.

Lets come to the the point:

Lets assume you have a website url: http://www.makemypost.com/blog/ and you want to run your website from something like http://blog.makemypost.com

You are viewing the right article. 🙂

Just copy and paste the below code in you .htaccess file, save it and you are done!!!

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

Well well well… we forget the following step(s):

**Create a subdomain using your cpanel with name blog.makemypost.com and point to the folder where the files are.

Try to run your website from http://www.makemypost.com/blog and see if it redirects you to http://blog.makemypost.com/. If you are able to see this you are lucky, you have made it!!!

Otherwise, go to your domain manager and create a A record for your subdomain, pointing to your hosting.

e.g. A Record => blog.makemypost.com xxx.x.x.x

Please let me know in case you have got something more to share, it might help me or our other friends.

Thanks

Related Post