0

I have 2 websites (old-domain.com and new-domain.com), I am a shutting old-domain.com down and what to redirect to the new-domain. So I added the rewrite and return lines into my conf files. The catch all (return 301 *) works without a warning, however when I go to a specific page (e.g. old-domain.com/page-1), I get a certificate warning:

This server could not prove that it is old-domain.com; its security certificate is from new-domain.com. This may be caused by a misconfiguration or an attacker intercepting your connection.

Both domains are on the same IP, below is my nginx setup:

new-domain.conf:

server {
   listen 80;
    server_name new-domain.com;
}
server { 
    listen 433;

    server_name new-domain.com;

    ssl_certificate             new-domain.cert;
    ssl_certificate_key         new-domain.cert_key;
    ssl_client_certificate      new-domain.client_cert_key;
}

old-domain.conf:

server { 
    listen 80;
    listen 433;

    server_name old-domain.com;

    ssl_certificate             old-domain.cert;
    ssl_certificate_key         old-domain.cert_key;
    ssl_client_certificate      old-domain.client_cert_key;

    #catch all - works, but causes invalid certificate
    rewrite ^/page-1 https://new-domain.com/differnt-path/page-1-extra permanent;

    #catch all - works without warning
    return 301 https://new-domain.com;

1 Answer 1

0

A rewrite is local white a redirect is not. You do need to end your rewrite with a redirect only in order to execute the redirect. You could also use matching locations for your "rewrites"...

old-domain.conf:

server { 
    listen 80;
    listen 433;

    server_name old-domain.com;

    ssl_certificate             old-domain.cert;
    ssl_certificate_key         old-domain.cert_key;
    ssl_client_certificate      old-domain.client_cert_key;

    location ~ ^/page-1 {
        return 301 https://new-domain.com/differnt-path/page-1-extra;
    }

    location ~ ^/page-2(/.*)?$ {
        return 301 https://new-domain.com/differnt-path/page-2-extra$1;
    }

    rewrite ^/page-3 https://page-3/ redirect; # http 302!!!

    #catch all - works without warning
    return 301 https://new-domain.com;
4
  • redirect is used for 301 (temp) redirect. I want to permanently redirect the page. Nov 10, 2019 at 16:01
  • That's totally okay. You simply have to add redirect after the code you already have in that line. This is, because a rewrite is not redirecting but rewriting the URL locally...
    – boppy
    Nov 10, 2019 at 16:04
  • Getting an error nginx: [emerg] invalid number of arguments in "rewrite" Nov 10, 2019 at 16:30
  • Sorry, I never tried to use redirect+permanent. It's not working. Only one option is valid. Please see my edited answer.
    – boppy
    Nov 10, 2019 at 16:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .