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 bar.example.com 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} ^bar.example.com$ [NC]
RewriteRule ^(.*)$ /folderName/$1 [L]

The rule above will point your subdomain and all its URLs to /subfolder/
For example, a request for bar.example.com/file.php 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 2 / 5. Vote count: 4

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