Want more timely Centmin Mod News Updates?
Become a Member

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 Well-Known Member

    2,820
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    12:53 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    30,947
    6,915
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,413
    Local Time:
    8:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    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 Well-Known Member

    2,820
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    12:53 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    30,947
    6,915
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,413
    Local Time:
    8:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    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 Well-Known Member

    2,820
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    12:53 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    30,947
    6,915
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,413
    Local Time:
    8:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    don't need to touch existing redirect as that is for newdomain.com not old domain
     
  7. pamamolf

    pamamolf Well-Known Member

    2,820
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    12:53 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    30,947
    6,915
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,413
    Local Time:
    8:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    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;
     
    • Like Like x 1
  9. Colin

    Colin Premium Member Premium Member

    122
    35
    28
    Oct 7, 2015
    Sheffield UK
    Ratings:
    +87
    Local Time:
    10:53 PM
    1.11.#
    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

    30,947
    6,915
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,413
    Local Time:
    8:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    AFAIK 301/302 redirects retain the juice SEO wise.