문제

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.

도움이 되었습니까?

해결책

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).

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top