Apache mod-rewrite and htaccess related Articles htaccess url-rewriting

Map a subdomain to subfolder with htaccess


Last Updated on April 15, 2021 by Amit

Reditect subdomain to subfolder using htaccess
With an htaccess rewrite ,it is quite possible to map your subdomain to subfolder if its not already pointing there.
Suppose, you just created a new subdomain named and its currently pointing to you root directory , you can simply use a RewriteRule to map it to a new folder.
This article will teach you all about how it can be done with just a few lines of htaccess code.
Okay, so you have created a new subdomain , and now want to map it to a different folder, the following rule can help you with that. Just copy and paste it to your htaccess file and don’t forget to change the domain name.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$ /folderName/$1 [L]

The rule above will point your subdomain and all its URLs to /subfolder/
For example, a request for will be served from /subfolder/file.php . This doesn’t change the browser URL.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

By Amit

I am a freelance web developer/designer , blogger and StackOverflow contributer from India.

Leave a Reply

Your email address will not be published. Required fields are marked *