如何检测来自 CNAME 子域的传入请求(使用 PHP 脚本)? [英] How To Detect An Incoming Request (With PHP Script) From a CNAME Subdomain?

查看:34
本文介绍了如何检测来自 CNAME 子域的传入请求(使用 PHP 脚本)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个简单的基于 php 的重定向应用程序.

We have a simple php based redirection application.

这是一个例子:

spiderman.com/redirection/redirect-to-marvel/

php 脚本位于redirection"文件夹中,假设它将上面的链接重定向到 marvel.com

The php script is in the "redirection" folder and let's say it will redirect the above link to marvel.com

现在...

如果我想创建一个名为 try.superman.com 的完全不同的子域,它会使用 CNAME 重定向到 spiderman.com/redirection/这个网址:

What if I want to create a totally different subdomain called try.superman.com which redirects using a CNAME to spiderman.com/redirection/ so that if I open this url:

try.superman.com/redirect-to-marvel/ 它实际上会转发到 spiderman.com/redirection/redirect-to-marvel/ 这当然会将其转发到 ma​​rvel.com

try.superman.com/redirect-to-marvel/ it will actually forward to spiderman.com/redirection/redirect-to-marvel/ which will of course forward it to marvel.com

简而言之,浏览器会显示try.superman.com/redirect-to-marvel/(由于CNAME),但是我如何在服务器端检测来自CNAME记录的传入请求,并对其进行路由到正确的本地文件夹?

In short, the browser will show try.superman.com/redirect-to-marvel/ (due to the CNAME), but how do I, at the server end detect the incoming request from a CNAME record, and route it to the correct local folder?

这里需要一些指导...

Just need some direction here...

PHP 的 dns_get_record + htaccess 方向正确吗?

PHP's dns_get_record + htaccess the right direction?

推荐答案

一个重要的区别是 CNAME 和重写/重定向(或 vhost)是完全不同的东西,经常会混淆.

An important distinction to make is that a CNAME and a rewrite/redirect (or vhost) are totally different things that often get confused.

CNAME 是一个 DNS 实体,因此您可以有多个名称指向一个单一的地址.例如,bob.example.com 是位于 1.2.3.4 的主机.然后,您可以为 alice.example.com 创建一个 CNAME,指向 bob 进行 DNS 解析并返回相同的 IP 地址.

A CNAME is a DNS entity so that you can have multiple names pointing to a singular address. For example, bob.example.com is a host that lives at 1.2.3.4. You can then create a CNAME for alice.example.com which points to bob for DNS resolution and returns the same IP address.

重定向是一种 HTTP 方法,用于接收到达特定位置的请求 (http://bob.example.com/index.html) 并向浏览器返回一个指令到其他地方 (http://alice.example.com/somewhereelse.html) 客户端的浏览器显示.

A redirect is an HTTP method to take a request that lands on a certain location (http://bob.example.com/index.html) and returns an instruction to the browser to go somewhere else (http://alice.example.com/somewhereelse.html) which the client's browser shows.

重写是一种 HTTP 方法,用于接收到达某个位置的请求,对其进行更改,然后将其发送到应答服务器,而不必让客户端的浏览器知道它已发生.

A rewrite is an HTTP method to take a request that lands on a certain location, change it, and then send it on to an answering server without necessarily letting the client's browser know that it's occured.

虚拟主机(vhost 等...同一个函数有不同的名称)是一种 HTTP 方法,它允许您通过查看请求使用的名称以不同的方式回答请求,通常是通过检查包含在每个请求中的 HTTP 主机标头.以上面为例:客户端请求http://alice.example.com,通过DNS解析为1.2.3.4 因为 alice 是 bob.example.com 的 CNAME.请求位于相同的 IP 地址 1.2.3.4,但在那里运行的 Web 服务器使用/alice 下的内容而不是/bob 下的内容来响应请求.

A virtualhost (vhost, etc...there are different names for the same function) is an HTTP method that allows you to answer a request in different ways by looking at the name that the request is using, often by examining the HTTP Host header that's included in every request. Take the above for example: client requests http://alice.example.com, which resolves via DNS to 1.2.3.4 because alice is a CNAME to bob.example.com. The request lands on the same IP address, 1.2.3.4, but the web server that's running there answers the request with the content under /alice instead of /bob.

希望有帮助

这篇关于如何检测来自 CNAME 子域的传入请求(使用 PHP 脚本)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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