为不存在的子域创建错误页面 [英] Creating an error page for a subdomain that doesn't exist

查看:203
本文介绍了为不存在的子域创建错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一些子域名。当有人进入不存在的子域时,我想重定向到我的主域中的404页面。



noexist.example.com - >示例。 com / 404.php?subdomain = noexist(或没有查询字符串,如果HTTP_REFERRER可以给我的信息)



我在安装了cPanel的VPS上运行LAMP。我可以通过WHM编辑该域的DNS区域文件。

解决方案

几分钟后,我的服务器支持中心,我终于获得通配符子域设置。



现在,当用户访问subdomain.example.com时,如果该子域通过cPanel显式设置,它将正常运行。如果该子域未被明确设置,那么它将被间接重定向到example.com,在那里我可以抓住他们使用的子域,并根据需要处理它(显示页面,重定向到子域或显示404错误)。


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

这篇关于为不存在的子域创建错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆