I wanted to redirect a subdomain ( websites.bizanosa.com) to another subdomain (p.bizanosa.com) . I searched online for a direct solution but didn’t find one.
Eventually, trying out different options I was able to mashup some results I found online to give me the following. And it works for me.
If you are in the same boat , you can try it and see if it works for you .
RewriteEngine on RewriteCond %{HTTP_HOST} ^websites\.bizanosa\.com [NC,OR] RewriteCond %{HTTP_HOST} ^www\.websites\.bizanosa.com [NC] RewriteRule ^(.*)$ https://p.bizanosa.com/$1 [L,R=301,NC]
My subdomains are websites.bizanosa.com and p.bizanosa.com . Replace them with yours .
This part…
RewriteCond %{HTTP_HOST} ^websites\.bizanosa\.com [NC,OR]
Redirects the subdomain, websites.bizanosa.com that has no www .
And this part
RewriteCond %{HTTP_HOST} ^www\.websites\.bizanosa.com [NC]
Redirects the subdomain, www.websites.bizanosa.com that has www .
And everything gets redirected to p.bizanosa.com
RewriteRule ^(.*)$ https://p.bizanosa.com/$1 [L,R=301,NC]
Note :
- This is a WildCard redirect . It will redirect every link from website.bizanosa.com .
- To redirect from a domain to a domain .You can use the same code by removing the subdomain parts.
Hope it saves you time .