Pregunta

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.

noexist.example.com --> example.com/404.php?subdomain=noexist (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.

¿Fue útil?

Solución

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

Now when a user goes to subdomain.example.com, 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 example.com, 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).

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top