imos/domainredirector

此软件包已被废弃,不再维护。没有建议的替代包。

imos 域名重定向器,用于将入站请求重定向到正确的域名

v0.5 2017-07-13 07:58 UTC

This package is not auto-updated.

Last update: 2023-02-18 09:58:59 UTC


README

Build Status

网站有时拥有许多二级域名。为了满足SEO需求并使其正确,每个网站应该只有一个主域名。这个库是为了管理网站的域名配置而设计的。特别之处在于,您可以配置多个主域名(这在多站点环境中非常有用)。

使用方法

require 'vendor/autoload.php';
use Imos\DomainRedirector\DomainRedirector;
use Symfony\Component\HttpFoundation\Request;

// create object
$domainRedirector = new DomainRedirector();

// add primary domain and the corresponding secondary domains
$domainRedirector->addPrimaryDomain('www.imos.net', true); // second argument = ssl
$domainRedirector->addSecondaryDomain('www.imosnet.de', 'www.imos.net'); // www.imosnet.de should redirect to www.imos.net
$domainRedirector->addSecondaryDomain('www.anotherdomain.de', 'www.imos.net'); // ...

// if we have another primary domain, we could add it here
$domainRedirector->addPrimaryDomain('www.another-domain.de');
$domainRedirector->addSecondaryDomain('www.foobar.de', 'www.another-domain.de');

// we can even add a fallback, for requests that does not match any domain
$domainRedirector->setFallbackDomain('www.imos.net');

// pass a symfony request object to $domainRedirector. For example we fake some requests:

$request = Request::create('/de/test.html?x=y', 'GET', [], [], [], ['HTTP_HOST' => 'www.imosnet.de']);
$redirectUrl = $domainRedirector->getRedirect($request); // https://www.imos.net/de/test.html?x=y

$request = Request::create('/de/test.html?x=y', 'GET', [], [], [], ['HTTP_HOST' => 'www.imos.net', 'HTTPS' => 'ON']);
$redirectUrl = $domainRedirector->getRedirect($request); // false (everything is fine, we dont need any redirect)

$request = Request::create('/de/test.html?x=y', 'GET', [], [], [], ['HTTP_HOST' => 'www.foobar.de']);
$redirectUrl = $domainRedirector->getRedirect($request); // http://www.another-domain.de/de/test.html?x=y

// fallback example
$request = Request::create('/de/test.html?x=y', 'GET', [], [], [], ['HTTP_HOST' => 'www.xyz.de']);
$redirectUrl = $domainRedirector->getRedirect($request); // https://www.imos.net/de/test.html?x=y

许可协议

这是一个开源软件,许可协议为MIT许可协议