Creating an error page for a subdomain that doesn't exist

I've got a number of subdomains on one of my sites. When someone goes to a subdomain that doesn't exist, I want to redirect to a 404 page on my main domain. --> (or without the query string if HTTP_REFERRER can give me that info)

I'm running LAMP on a VPS with cPanel installed. I can edit the DNS Zone file for the domain via WHM.


After a few hours ticketing my server's support center, I finally got wildcard subdomains set up.

Now when a user goes to, if that subdomain was explicitly set up via cPanel, it will function appropriately. If that subdomain was not explicitly set up then it will be interally redirected to, where I can grab the subdomain that they used and handle it as necessary (show a page, redirect to a subdomain, or show a 404 error).

There are a ton of tutorials on how to create a custom 404 page, no need to redirect as apache should take care of this for you.

Need Your Help

How to preprocess steps on Apache before sending a page to the User

apache apache-modules

I have an Apache web server and I need to do some processes outside the web server when a user requests a certain page.

How to sync Ctrl+mousewheel across controls?


I have a class which handles a scrollbar PreviewMouseWheel event which zooms a timeline control, and everything works perfectly, except that I have to be over the scrollbar for the clr+mouse zoom to