Discover Centmin Mod today
Register Now

Wordpress Change domain of WordPress and do 301 wildcard redirect

Discussion in 'Blogs & CMS usage' started by Afaq, Nov 20, 2017.

Tags:
  1. Afaq

    Afaq Member

    61
    1
    8
    Aug 5, 2015
    Ratings:
    +2
    Local Time:
    6:28 AM
    I have a WordPress website running on Centminmod. I want to change its domain and name. Now, I know what I have do on WordPress' end but I want to know how can I manage this migration on centmin mod. And ultimately, I want a 301 wildcard redirect from old domain to new one.
    Thanks.
     
  2. eva2000

    eva2000 Administrator Staff Member

    31,021
    6,924
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,430
    Local Time:
    11:28 AM
    Nginx 1.13.x
    MariaDB 5.5
    do not delete the old domain nginx vhost config files, just edit their server{} context and do a 302 temp redirect to the new domain and let that run for a few weeks to be sure before changing to 301 permanent redirect

    key to testing is using 302 temp redirect first in a private incognito browser session otherwise the problems you can experience may end up being due to browser caching or 301 permanent redirects unless you clear browser cache and reboot local computer(s) and even then some web browsers don't let go of 301 permanent redirect browser cache that willingly :)

    You can test in SSH via curl to check headers for location field (where the redirect goes) using the following commands:
    Code (Text):
    curl -I http://domain.com
    

    Code (Text):
    curl -I http://www.domain.com
    
     
  3. Afaq

    Afaq Member

    61
    1
    8
    Aug 5, 2015
    Ratings:
    +2
    Local Time:
    6:28 AM

    Thanks for the response.

    So if I lay it out step by step, here is what I should do:
    1. Create a new vhost for the new domain.
    2. Copy the files from old vhost to new vhost.
    3. Copy the nginx config of old vhost to new one and replace the old domain with new domain.
    4. Now, my new website would be live.
    5. Now, setup a 302 redirect in the old vhost config file.

    and that's all.

    Can you also please tell what would be the correct way to put a 302 or 301 redirect with wildcard?
    and lastly, if I want to delete the old vhost from the server, where will I put the redirect?
     
  4. eva2000

    eva2000 Administrator Staff Member

    31,021
    6,924
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,430
    Local Time:
    11:28 AM
    Nginx 1.13.x
    MariaDB 5.5
    correct
    Might want to checked out these guides
    particularly https://www.nginx.com/blog/creating-nginx-rewrite-rules/

    for domain redirects using return directive is best within it's server{} context so to redirect old-name.com and it's equivalent www version to the new-name.com www version would be
    Code (Text):
    server {
       server_name old-name.com www.old-name.com;
       return 302 $scheme://www.new-name.com$request_uri;
    }
    

    this technically can be placed in your old domain nginx vhost, or if you remove it, in your new domain nginx vhost as separate server{} context

    so your vhost below would redirect old-name.com and it's equivalent www version + non-www new-name.com domain to the new-name.com www version via 3 separate server{} contexts in the new domain nginx vhost file
    Code (Text):
    server {
       server_name old-name.com www.old-name.com;
       return 302 $scheme://www.new-name.com$request_uri;
    }
    
    server {
       server_name new-name.com;
       return 302 $scheme://www.new-name.com$request_uri;
    }
    
    server {
       server_name www.new-name.com;
       ... your vhost config settings ....
    }