Pantheon 不使用 htaccess 文件,因为它不使用 Apache。 Pantheon 使用 Varnish 和 Nginx 结合快速 CDN 现在是所有更新的 HTTPS 安装的标准。
“重定向应该在 PHP 中管理,因为 .htaccess 被忽略。有关详细信息,请参阅使用 PHP 作为 htaccess 替代方案。”
https://pantheon.io/docs/htaccess/
在 settings.php 中使用 HTTPS 配置重定向到主域
Pantheon 的重定向设置非常独特。它能够允许 PHP 重定向直接进入清漆层,而没有 PHP 重定向的传统延迟。
对于 Drupal 7,将以下内容添加到 settings.php 文件的末尾(替换 www.example.com):
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) && php_sapi_name() != 'cli') {
// Redirect to https://$primary_domain in the Live environment
if ($_ENV['PANTHEON_ENVIRONMENT'] === 'live') {
/** Replace www.example.com with your registered domain name */
$primary_domain = 'www.example.com';
}
else {
// Redirect to HTTPS on every Pantheon environment.
$primary_domain = $_SERVER['HTTP_HOST'];
}
if ($_SERVER['HTTP_HOST'] != $primary_domain
|| !isset($_SERVER['HTTP_X_SSL'])
|| $_SERVER['HTTP_X_SSL'] != 'ON' ) {
# Name transaction "redirect" in New Relic for improved reporting (optional)
if (extension_loaded('newrelic')) {
newrelic_name_transaction("redirect");
}
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://'. $primary_domain . $_SERVER['REQUEST_URI']);
exit();
}
}
看
https://pantheon.io/docs/guides/launch/redirects/
https://pantheon.io/docs/domains/
对于 HTTPS
https://pantheon.io/docs/http-to-https/
重定向到子目录或特定网址
要从子域重定向到站点的特定区域,请使用以下命令:
// Redirect subdomain to a specific path.
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) &&
($_SERVER['HTTP_HOST'] == 'subdomain.yoursite.com') &&
// Check if Drupal or WordPress is running via command line
(php_sapi_name() != "cli")) {
$newurl = 'http://www.yoursite.com/subdomain/'. $_SERVER['REQUEST_URI'];
header('HTTP/1.0 301 Moved Permanently');
header("Location: $newurl");
exit();
}
对于 Drupal 8(认为这可能也有帮助,因为 Drupal 8 和 Drupal 7 的重定向设置略有不同)
将以下内容添加到 settings.php 文件的末尾(替换 www.example.com):
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) && php_sapi_name() != 'cli') {
// Redirect to https://$primary_domain in the Live environment
if ($_ENV['PANTHEON_ENVIRONMENT'] === 'live') {
/** Replace www.example.com with your registered domain name */
$primary_domain = 'www.example.com';
}
else {
// Redirect to HTTPS on every Pantheon environment.
$primary_domain = $_SERVER['HTTP_HOST'];
}
if ($_SERVER['HTTP_HOST'] != $primary_domain
|| !isset($_SERVER['HTTP_X_SSL'])
|| $_SERVER['HTTP_X_SSL'] != 'ON' ) {
# Name transaction "redirect" in New Relic for improved reporting (optional)
if (extension_loaded('newrelic')) {
newrelic_name_transaction("redirect");
}
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://'. $primary_domain . $_SERVER['REQUEST_URI']);
exit();
}
// Drupal 8 Trusted Host Settings
if (is_array($settings)) {
$settings['trusted_host_patterns'] = array('^'. preg_quote($primary_domain) .'$');
}
}