重定向任意子域名页面,$ _GET信息 [英] Redirect arbitrary subdomain to page with $_get info

查看:206
本文介绍了重定向任意子域名页面,$ _GET信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,是建立和运行,并已经得到了另一个域和需求的重定向任何访问 exampleA.com 或分域的话,一个页面,其中的我可以检查的要求页的子域名网站的动态列表,如果它匹配的它<$ C $发送到该子域C> exampleB.com ,如果不是对 exampleB.com 。不会有任何网站都在 exampleA.com 是主域名只是一个较短的版本。主要的网站是一个字preSS网站。

I have a site that is up and running and have gotten another domain and need redirect any visit to exampleA.com or any sub-domain of it, to a page where I can check the requested page's sub-domain to a dynamic list of sites and if its a match send it to that sub-domain on exampleB.com, and if not send it to the main site on exampleB.com. there will be no site at all on exampleA.com is is just a shorter version of the main domain. The main site is a wordpress site.

我有什么。

我有 exampleA.com exampleB.com exampleB.com 有子域。

我需要什么。

重定向 *。exampleA.com exampleB.com/somePage/?from = *

在它到达 exampleB.com/somePage/?from = * 我可以检查 $ _ GET 信息。但我不知道如何将任意子域设置为 $ _ GET

After it gets to exampleB.com/somePage/?from=* I can check the $_GET info. but I'm not sure how to set the arbitrary sub-domain to the $_GET

推荐答案

您会需要几件事情:

一)exampleA.com的DNS设置必须被配置为允许通配符子域:

a) exampleA.com's DNS setup must be configured to allow wildcard subdomains:

*.exampleA.com. 3600 IN A x.x.x.x

二)exampleA.com的Web服务器配置必须允许通配符主机匹配

b) exampleA.com's web server configuration must allow wildcard host matching

<VirtualHost ...>
    ServerName exampleA.com
    ServerAlias *.exampleA.com
</VirtualHost

C)exampleA.com的默认文档将提取的主机名使用并发出重定向例B与提取的主机名。一个简单的PHP脚本

c) exampleA.com's default document would be a simple PHP script that extracts the hostname in use and issues a redirect to exampleB with the extracted host name.

<?php

$requested_host = $_SERVER['HTTP_HOST'];

$parts = explode('.', $requested_host);
array_pop($parts); // com
array_pop($parts); // exampleA

$requested_subhost = implode('.', $parts);

header("Location: http://exampleB.com/?from=$requested_subhost");

这篇关于重定向任意子域名页面,$ _GET信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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