Let's talk now.
407-476-6930 / 850-366-8392 (PCB)

Redirect all subdomains to a URL

by Brandon Welch
Web Designer/Developer & Web Expert
Connect with me: | Facebook | LinkedIn

There may be cases where you want to redirect all subdomains to a main domain. Maybe consolidating an older larger site that used subdomains for everything instead of directory structure. The below code should be just want you need.

The Code:
RewriteEngine On
2.RewriteBase /
3.RewriteCond %{HTTP_HOST} !^yourdomain.com$ [NC] 4.RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

What This Does:
This makes sure the url starts with the domain you specify/ If the url starts with anything else, it will be redirected. This should handle redirection to the proper page, and handle www.

Note: This is a permanent redirect.