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: and you want to run your website from something like

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} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]
RedirectMatch 301 ^/blog/(.*)$$1

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

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

Try to run your website from and see if it redirects you to 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 => 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.


Related Post


admin has written 4 articles