.htaccess 在上传到万神殿服务器时无法在 drupal 7 上运行

.htaccess not working on drupal 7 when uploaded to pantheon server

我的 drupal 站点有一个 .htaccess 文件,我在 redirecting 页面上没有更改 URL,它在 local server 和其他 [=14] 上工作正常=] 但是当我将文件和数据库上传到 pantheon server 时,它不会重定向页面说 404 not found。我将 .htaccess 放在 code 文件夹的根目录下,我尝试将它放在 server root 文件夹、sites 文件夹和 themes 文件夹中,但对我没有任何作用。任何人都可以知道 pantheondrupal 站点中 .htaccess 的正确位置是什么?为什么我的 .htaccess 无法在 pantheon 上工作?

Pantheon 运行 nginx,它会忽略 .htaccess 文件。

因为 Pantheon 服务器使用 Nginx,并且它们不启用 .htaccess 支持。

您应该直接联系他们讨论您的选择。

但是,您可以使用 Drupal 的 settings.php 执行重定向,请参阅:

https://pantheon.io/docs/articles/sites/code/redirect-incoming-requests/

技术上 运行 Nginx with varnish。 redirects & redirect incoming requests

// 301 Redirect from /old to /new.
if (($_SERVER['REQUEST_URI'] == '/old') &&
  (php_sapi_name() != "cli")) {
  header('HTTP/1.0 301 Moved Permanently');
  header('Location: /new');
  exit();
}

Pantheon 不使用 htaccess 文件 发现因为它不使用 Apache。 Pantheon 使用 Varnish 和 Nginx 结合快速 CDN 现在是所有更新的 HTTPS 安装的标准。

"Redirects should be managed in PHP, since .htaccess is ignored. For details, see Using PHP as an htaccess Alternative." https://pantheon.io/docs/htaccess/

在 settings.php

中使用 HTTPS 配置重定向到主域

万神殿的重定向设置非常独特。它能够允许 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/

重定向到子目录或特定 URL

要从子域重定向到网站的特定区域,请使用以下内容:

// 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) .'$');
  }
}