问题
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.
回答1:
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).
回答2:
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.
- http://www.webmonkey.com/2010/02/create_custom_404_pages/
- http://www.thesitewizard.com/archive/custom404.shtml
- http://www.yourhtmlsource.com/sitemanagement/custom404error.html
来源:https://stackoverflow.com/questions/3858385/creating-an-error-page-for-a-subdomain-that-doesnt-exist