Redirect rule | subdomain to main domain | htaccess

If you have a subdomain and want to redirect it to your main domain, then this post provides the redirect rule that you have to add in .htaccess file in sub-domain’s root directory.

Also read: Serve static content like images from subdomain to increase website page speed

For example, if your subdomain is and main domain is, then the htaccess redirect rule is

RewriteEngine On
RewriteCond %{HTTP_HOST} ^img\.example\.com  [NC]
RewriteRule ^(.*)$1 [L,R=301]
  1. Replace with your domain name
  2. Replace img with your subdomain name
  3. Create a empty .htaccess file at root directory of sub-domain
  4. Copy the above updated redirect rule to htaccess file and upload
  5. Check whether the subdomain pages redirect to main domain

So, if you enter, it redirects to

About the Author


A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

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