我的drupal网站有一个.htaccess
文件,我在redirecting
页面没有更改URL
,它在local server
和其他servers
工作正常,但当我上传文件和数据库到pantheon server
它不会重定向页面说404 not found
。我把.htaccess
放在code
文件夹的根部,我尝试将它放在server root
文件夹,sites
文件夹和themes
文件夹中,但没有任何对我有用。任何人都可以知道在.htaccess
的drupal
网站上pantheon
的正确位置是什么?为什么我的.htaccess
没有在pantheon
工作?
因为Pantheon服务器使用Nginx,并且它们不支持.htaccess支持。
您应该直接与他们联系,讨论您的选择。
但是,您可以使用Drupal的settings.php执行重定向,请参阅:
https://pantheon.io/docs/articles/sites/code/redirect-incoming-requests/
Pantheon运行nginx,忽略.htaccess文件。
技术上运行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();
}
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) .'$');
}
}