我们有一个 Drupal 8 网站,运行大约 18 种语言,但只有中文版有单独的域名。我们希望这个域名(出于测试目的,为 testchinese.com)在后台重定向到 drupalwebsite.com/zh-hans,其中 zh-hans 是中文版的语言代码。
这是我们尝试过的,它重定向,但 URL 也发生了变化:
server {
listen 80;
listen [::]:80;
#listen 443 ssl;
#listen [::]:443 ssl;
server_name testchinese.com;
location /core/assets {
alias /var/www/production/core/assets;
try_files $uri $uri/;
}
location /zh-hans {
rewrite ^/zh-hans(.*)$ $1 redirect;
}
location / {
proxy_pass https://127.0.0.1/zh-hans$request_uri;
proxy_set_header Host drupalwebsite.com;
}
}
server {
listen 80;
listen [::]:80;
server_name drupalwebsite.com;
return 301 https://drupalwebsite.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name drupalwebsite;
ssl on;
ssl_certificate /etc/letsencrypt/live/drupalwebsite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/drupalwebsite/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
root /var/www/production;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
location /pMA {
alias /var/www/production/pMA;
index index.php index.html;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \..*/.*\.php$ {
return 403;
}
location ~ ^/sites/.*/private/ {
return 403;
}
# Block access to scripts in site files directory
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}
# Allow "Well-Known URIs" as per RFC 5785
location ~* ^/.well-known/ {
allow all;
}
# Block access to "hidden" files and directories whose names begin with a
# period. This includes directories used by version control systems such
# as Subversion or Git to store control files.
location ~ (^|/)\. {
return 403;
}
location / {
try_files $uri /index.php?$query_string;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
# Don't allow direct access to PHP files in the vendor directory.
location ~ /vendor/.*\.php$ {
deny all;
return 404;
}
# In Drupal 8, we must also match new paths where the '.php' appears in
# the middle, such as update.php/selection. The rule we use is strict,
# and only allows this pattern with the update.php front controller.
# This allows legacy path aliases in the form of
# blog/index.php/legacy-path to continue to route to Drupal nodes. If
# you do not have any paths like that, then you might prefer to use a
# laxer rule, such as:
# location ~ \.php(/|$) {
# The laxer rule will continue to work if Drupal uses this new URL
# pattern with front controllers other than update.php in a future
# release.
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
#include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
# Fighting with Styles? This little gem is amazing.
# location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
try_files $uri @rewrite;
}
# Handle private files through Drupal. Private file's path can come
# with a language prefix.
location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
try_files $uri /index.php?$query_string;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
任何帮助深表感谢!