使用 nginx 从别名 URL 重定向到主 URL

使用 nginx 从别名 URL 重定向到主 URL

我有一个在 Laravel Forge 上运行的网站,其主域名为 example.org,别名为 myolddomain.com

这意味着内容在两个网站上都可用。我想让访问 myolddomain.com/whatever 的人转到 example.org/whatever

我尝试添加重写规则,但最终导致重定向循环

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.org/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.org myolddomain.com;
    #rewrite ^/(.*)$ https://example.org/$1 permanent;

    root /home/forge/example.org/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/example.org/602515/server.crt;
    ssl_certificate_key /etc/nginx/ssl/example.org/602515/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers xxxxxxxxxx;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/example.org/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/example.org-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.org/after/*;

我错过了什么?

相关内容