Welcome to Centmin Mod Community
Register Now

Redirect from old domain to a new one keeping the link exact

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by pamamolf, Jan 9, 2017.

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    6:37 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Please fill in any relevant information that applies to you:
    • Centmin Mod Version Installed:123.09beta01
    • Nginx Version Installed: 1.11.8
    • PHP Version Installed:7.0.14
    • MariaDB MySQL Version Installed:10.1.20
    • When was last time updated Centmin Mod code base ? :today


    Hello :)

    I am wondering how can i redirect a user that request old domain links to forward him to the new domain link but keep the exact link like:

    user request:


    Code:
    http://forum.domain123.com/abc/123.php
    to be:

    Code:
    http://www.newdomain.com/abc/123.php
    Thanks
     
    Last edited: Jan 9, 2017
  2. eva2000

    eva2000 Administrator Staff Member

    54,857
    12,238
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,809
    Local Time:
    2:37 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    see https://www.nginx.com/blog/creating-nginx-rewrite-rules/ should be the same as using return 301/302 for http to https redirect so 2 separate server{} context for old and new domain where old domain has a return 301/302 to new domain
    Code (Text):
    server {
        listen 80;
        server_name www.old-name.com;
        return 302 $scheme://www.new-name.com$request_uri;
    }
     
  3. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    6:37 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    If the old domain was a subdomain do i have to create it first as a separate vhost and point an A record to it and do that change on that vhost config?

    confused a bit...

    Code:
    http://forum.domain123.com/abc/123.php
    to be:

    Code:
    http://www.newdomain.com/abc/123.php
     
  4. eva2000

    eva2000 Administrator Staff Member

    54,857
    12,238
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,809
    Local Time:
    2:37 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    technically you don't need the full vhost and files just the server{} context added to the new nginx vhost domain.com.conf and/or domain.com.ssl.conf
    Code (Text):
    server {
        listen 80;
        server_name forum.domain123.com;
        return 302 $scheme://www.newdomain.com$request_uri;
    }
     
  5. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    6:37 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    I have already use the second server {} for the www redirect :(

    How can i adjust it now?

    Code:
    server {
                listen   80;
                server_name newdomain.com;
                return 301 $scheme://www.newdomain.com$request_uri;
           }
    
    server {
     
      server_name newdomain.com www.newdomain.com;
     
  6. eva2000

    eva2000 Administrator Staff Member

    54,857
    12,238
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,809
    Local Time:
    2:37 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    don't need to touch existing redirect as that is for newdomain.com not old domain
     
  7. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    6:37 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    I was confused as you say added to the new vhost :)

    My bad english damn sorry :(

    So i will create another .conf file for http and another one for https and add there only this? :

    Code:
    server {
        listen 80;
        server_name forum.domain123.com;
        return 302 $scheme://www.newdomain.com$request_uri;
    }
     
  8. eva2000

    eva2000 Administrator Staff Member

    54,857
    12,238
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,809
    Local Time:
    2:37 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    can add to newdomain.com.conf or edit olddomain.com.conf if it exists
    i.e.
    Code (Text):
    server {
       listen 80;
       server_name forum.domain123.com;
       return 302 $scheme://www.newdomain.com$request_uri;
    }
    
    server {
      listen   80;
      server_name newdomain.com;
      return 301 $scheme://www.newdomain.com$request_uri;
    }
    
    server {
     
      server_name newdomain.com www.newdomain.com;
     
  9. Colin

    Colin Premium Member Premium Member

    192
    59
    28
    Oct 7, 2015
    Sheffield UK
    Ratings:
    +154
    Local Time:
    4:37 AM
    1.19.#
    MariaDB 10.1.#
    Partial hijack. For operational reasons only I was thinking of going the other way domain.com/forums -> forums.domain.com. What stopped me; there is no re-branding, was SEO. I've no idea how, despite various posting and video comments, google; others maybe, would treat such a move, a few million pages.

    Is this something you've considered or is it not an issue due to newdomain over olddomain?
     
  10. eva2000

    eva2000 Administrator Staff Member

    54,857
    12,238
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,809
    Local Time:
    2:37 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    AFAIK 301/302 redirects retain the juice SEO wise.