删除后面的斜线NGINX 2个网站的一个域名

我有以下NGINXconfiguration

server { listen 80; server_name www.cakein.local; rewrite_log on; # removes trailing slashes (prevents SEO duplicate content issues) #if (!-d $request_filename) { # rewrite ^/(.+)/$ /$1 permanent; #} location /en { alias /home/sites/cakein/en/webroot; index index.php try_files $uri /index.php?$args; location ~ ^/en(.*)\.php { index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$1.php; } } location / { root /home/sites/cakein/sk/webroot; index index.php index.html; try_files $uri /index.php?$args; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } } 

所以你可以看到,在以下scheme中有两个站点:

 sk -- ... -- webroot en -- ... -- webroot 

第一个站点(sk)挂在工作正常的“/”URI上,domain.tld

但是所有带“en”前缀的都失败了。 使用domain.tld / EN

EN版本有两个主要问题

  • “en”被redirect到“en /”我怎么能防止这个?
  • URL重写不起作用,所以domain.tld / en / moribundus返回404。

由于长期存在的问题 ,在同一个location块中使用aliastry_files可能会导致问题。

此外,您的默认行为是发送/en//index.php ,这是错误的URI,应该是/en/index.php

尝试:

 location /en { alias /home/sites/cakein/en/webroot; index index.php if (!-e $request_filename) { rewrite ^ /en/index.php last; } ... } 

编辑:

修复/en /en/ redirect的一种可能的方法是添加另一个location块:

 location = /en { rewrite ^ /en/ last; }