.htaccess上传到万神殿服务器时没有在drupal 7上工作

时间:2015-04-16 14:59:22

标签: .htaccess drupal drupal-7 pantheon

我的drupal网站有一个.htaccess文件,我在redirecting页面上没有更改URL,其工作正常local server&其他servers但是当我上传文件时数据库到pantheon server它不会重定向显示404 not found的页面。我将.htaccess放在code文件夹的根目录下,我尝试将其放在server root文件夹,sites文件夹和文件夹中。 themes文件夹,但对我没什么用。任何机构都可以知道.htaccess drupal网站pantheon.htaccess的正确位置吗? &安培;为什么我的pantheon无法处理{{1}}?

4 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

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

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

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

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

答案 2 :(得分:0)

技术上运行带有清漆的Nginx。 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();
}

答案 3 :(得分:0)

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