Magnus V.
Magnus V.

Reputation: 43

Subdomain wildcard redirect

I'm running a minor WordPress (multisite/network) site, on a server using cPanel. The site used to have a lot of subdomains like:

The problem:
Most of the subdomains are no longer available (neither in the DNS nor anywhere else) - so when you try to reach shop.example.com it just hits a 404.

So my question is:
How do I get all subdomains to redirect to example.com?

What have i done/tried already:

So what am I doing wrong? I'm pretty sure I need to do a combination of setting up a wildcard DNS record, and doing something in CPanel :P - but I just can't figure out exactly what.

Upvotes: 1

Views: 850

Answers (1)

Katie
Katie

Reputation: 2693

From your post

Doing this forced it onto the server, so its no longer just a 404, but the server doesn't recognize shop.example.com

You then need to do a 301 Redirect from shop.example.com to wherever you want to go, you can do this is in the CPanel. You will have to do this for each subdomain that that once existed therefore handling any requests that might come.

Unfortunately, there isn't a way to use the wildcard like you can for the IP. Each subdomain is a separate website as far as the webserver software, such as Apache, is concerned. So when you do a redirect you are answering the webserver software question, "OK, I got a HTTP GET request for shop.example.com, what files do I serve up? "

See this section in the CPanel docs for more information on redirecting.

Upvotes: 1

Related Questions