0

I have a site running on Laravel Forge that has a primary domain of example.org and then an alias of myolddomain.com

This means that content is available at both. I'd like to make it that if someone visits myolddomain.com/whatever that they are taken to example.org/whatever

I've tried adding rewrite rules but end up with redirect loops

# 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/*;

what am I missing?

Steven Grant
  • 101
  • 2
  • 1
    You need to split it into two separate `server` blocks. The old domain only needs a `return 301 $scheme://example.com$request_uri;` – Richard Smith May 09 '20 at 11:39
  • does it matter the order? – Steven Grant May 09 '20 at 12:08
  • 1
    The order determines which block is the default unless one is explicitly marked with the `default_server` attribute. It doesn't matter with respect to the domains defined using `server_name` directives. See [this document](http://nginx.org/en/docs/http/server_names.html#miscellaneous_names) – Richard Smith May 09 '20 at 12:40

0 Answers0