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

浪尽此生 提交于 2019-12-06 11:23:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!