how to redirect subdomain to root domain?

thashytt

Registered Member
Joined
Feb 24, 2015
Messages
93
Reaction score
15
Hello,

So i recently purchased an expired domain and many of its links are pointed to a subdomain. I cant seem to figure out how to 301 redirect through .htaccess - anyone can help me out it would be greatly appreciated.


For example this is my goal:

subdomain.domain.com/post1 -->>> domain.com/post1
subdomain.domain.com/post2 -->>> domain.com/post2

and so forth.

Do i need to set back up the subdomain in DNS before i try to 301 through htaccess?
 
I haven't tested it, but this .htaccess code should do the trick:

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
 
Hello,

So i recently purchased an expired domain and many of its links are pointed to a subdomain. I cant seem to figure out how to 301 redirect through .htaccess - anyone can help me out it would be greatly appreciated.


For example this is my goal:

subdomain.domain.com/post1 -->>> domain.com/post1
subdomain.domain.com/post2 -->>> domain.com/post2

and so forth.

Do i need to set back up the subdomain in DNS before i try to 301 through htaccess?


Is it a WordPress website?
 
Back
Top