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

问题描述 投票:1回答:4

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

.htaccess drupal drupal-7 pantheon
4个回答
1
投票

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

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

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

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


1
投票

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


0
投票

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

0
投票

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

“重定向应该在PHP中管理,因为.htaccess被忽略。有关详细信息,请参阅将PHP用作htaccess替代方案。” 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) .'$');
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.