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 img.example.com and main domain is example.com, then the htaccess redirect rule is
RewriteEngine On
RewriteCond %{HTTP_HOST} ^img\.example\.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [L,R=301]
- Replace example.com with your domain name
- Replace img with your subdomain name
- Create a empty .htaccess file at root directory of sub-domain
- Copy the above updated redirect rule to htaccess file and upload
- Check whether the subdomain pages redirect to main domain
So, if you enter img.example.com/page1.html, it redirects to https://www.example.com/page1.html