如何检测传入的请求(在PHP脚本)从CNAME子域?脚本、PHP、CNAME

2023-09-02 00:19:17 作者:︶ㄣ站在坟头蹦迪

我们有一个简单的PHP的重定向的应用程序。

We have a simple php based redirection application.

下面是一个例子:

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

PHP脚本是在重定向文件夹,让我们说,这将重定向到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 / 这当然会其转发给 marvel.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和重写/重定向(或虚拟主机)是完全不同的事情,往往会感到困惑。

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的主机。然后,您可以创建一个CNAME为alice.example.com指向先令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://鲍勃.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.

一个虚拟主机(虚拟主机,等等有不同的名称相同的功能)的HTTP方法,可以让你通过看名字,该请求被使用,通常通过检查来回答不同的方式请求多数民众赞成包含在每个请求的HTTP Host头。就拿上面的例子:客户端请求 http://alice.example.com ,通过DNS解析为1.2。 3.4,因为Alice是一个CNAME到bob.example.com。在同一个IP地址,1.2.3.4,但是我们在那里运行Web服务器的请求,土地回答下/而不是爱丽丝/鲍勃内容的请求。

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.

希望帮助

 
精彩推荐
图片推荐