Answer the question
In order to leave comments, you need to log in
How to replace Base URL and Request URI in Drupal 8 depending on $_SERVER['SERVER_ADDR']?
Please tell me how to configure Drupal 8 for TLS gateway.
There is a regular site address:
https://site.ru/
For the same site, there is a secure TLS gateway that forwards the regular site address to a new address:
https://tls.site.ru/subdirectory/
The site began to open at a new address , but with incorrect links to web resources.
For example, in user forms, the action leads to the old address (both in the admin panel and in forms on the client side). Example:
You need to make sure that the value of the action attribute contains the value "/subdirectory/node/1?destination=/node/1", similarly, in links to css styles and js scripts, "/subdirectory" is added to the beginning of the path.
<form action="/node/1?destination=/node/1" ...
For Drupal 7 in my /var/www/html/sites/default/settings.php this problem was solved like this:
$base_url = 'https://site.ru'; // NO trailing slash!
// URL TLS
$url_tls = 'tls.site.ru';
// URL TLS Path
$url_tls_path = '/subdirectory';
// URL TLS Gateway
$url_tls_gateway = 'https://' . $url_tls . $url_tls_path;
// Вход осуществляется по защищенному каналу или нет
$is_tls_gateway = FALSE;
// IP-адрес сервера, на котором выполняется текущий скрипт
$server_addr = $_SERVER['SERVER_ADDR'];
// IP-адрес интерфейса TLS
$ip_tls = '10.10.100.1';
if ($server_addr === $ip_tls) {
// Заменить Base URL
$base_url = $url_tls_gateway;
// Заменить Request URI
$_SERVER['REQUEST_URI'] = $url_tls_path . $_SERVER['REQUEST_URI']; // не работает в Drupal 8
// TLS используется
$is_tls_gateway = TRUE;
}
// Используется ли TLS Gateway
define('IS_TLS_GATEWAY', $is_tls_gateway);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question