为不存在的子域创建错误页面

发布于 2024-09-25 17:31:37 字数 226 浏览 0 评论 0原文

我的一个网站上有许多子域。当有人访问不存在的子域时,我想重定向到我的主域上的 404 页面。

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜警司 2024-10-02 17:31:37

经过几个小时向我的服务器支持中心提交票务后,我终于设置了通配符子域。

现在,当用户访问 subdomain.example.com 时,如果该子域是通过 cPanel 显式设置的,它将正常运行。如果该子域没有明确设置,那么它将被内部重定向到 example.com,我可以在其中获取他们使用的子域并根据需要进行处理(显示页面、重定向到子域或显示 404 错误)。

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

幻梦 2024-10-02 17:31:37

有大量关于如何创建自定义 404 页面的教程,无需重定向,因为 apache 应该会为您处理这个问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文