【问题标题】:.htaccess not working on drupal 7 when uploaded to pantheon server.htaccess 在上传到万神殿服务器时无法在 drupal 7 上运行
【发布时间】:2015-06-23 02:10:26
【问题描述】:

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

【问题讨论】:

  • 检查你的服务器重写模式

标签: .htaccess drupal drupal-7 pantheon


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

      【解决方案3】:

      技术上使用 varnish 运行 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();
      }
      

      【讨论】:

      • 你能再解释一下这个解决方案吗?
      • 嗨@TimS。 Pantheon 使用 Fastly 进行重定向是新的 CDN / 重定向是在边缘完成的,所以 Pantheon 上的 301 是唯一的 [pantheon 重定向] (pantheon.io/docs/guides/launch/redirects),因为服务器根本不使用 Apache,因此,不能使用 Apache HTaccess 所以为了替换 Apache,他们使用 Nginx、Varnish 和一个名为 Fastly 的 All Varnish CDN,他们要求您使用看看这个 [htaccess Alternative] (pantheon.io/docs/htaccess) 我希望对您有所帮助,Tom
      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 2016-01-27
        • 1970-01-01
        • 2019-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多