skip to Main Content

I have a client that entered the Cpanel, I copied it and pasted it from the wordpress folder domain1.cl to domino2.cl. What wp file are the URLs for the site to point to the new domain?
*Note: the client has already configured the new DNS, only the redirection is failing in WordPress. What is the best alternative to fix this?

2

Answers


  1. Chosen as BEST ANSWER

    Thanks! but i found plugin all-in-one in wp, and this solve all my problems, the only thing i had to do is change the BD to the new domain and chang the user and password of this.


  2. Please see the attack bash code bellow. Save it as update-wordpress-domain.sh for example and then do a chmod +x on it. Please edit/change/modify the db name, db user and password in the script the run it. It will ask for old domain and then for new domain. Then it will do the necessary changes:

    #!/bin/bash
    
    SQL_USER="db-user"
    SQL_PASS="db-password"
    SQL_DB="db-name"
    
    echo -e "Enter old domain: c"
    read OLD_DOMAIN
    echo -e "Enter new domain: c"
    read NEW_DOMAIN
    
    if [ -z "$OLD_DOMAIN" ] || [ -z "$NEW_DOMAIN" ]; then
        echo "old url and/or new url are empty. please define them!"
        exit 1
    fi
    
    # Save a mysqldump first!
    DATE=`date -I`
    
    mysqldump --opt -u $SQL_USER -p$SQL_PASS $SQL_DB > $SQL_DB.$DATE.sql
    
    echo "Updating the database"
    
    mysql -u $SQL_USER -p$SQL_PASS $SQL_DB -e "UPDATE wp_options SET option_value = replace(option_value, 'http://$OLD_DOMAIN', 'http://$NEW_DOMAIN') WHERE option_name = 'home' OR option_name = 'siteurl';"
    mysql -u $SQL_USER -p$SQL_PASS $SQL_DB -e "UPDATE wp_posts SET guid = replace(guid, 'http://$OLD_DOMAIN','http://$NEW_DOMAIN');"
    mysql -u $SQL_USER -p$SQL_PASS $SQL_DB -e "UPDATE wp_posts SET post_content = replace(post_content, 'http://$OLD_DOMAIN', 'http://$NEW_DOMAIN');"
    mysql -u $SQL_USER -p$SQL_PASS $SQL_DB -e "UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://$OLD_DOMAIN','http://$NEW_DOMAIN');"
    echo ""
    echo "Done!"
    

    Then run it as ./update-wordpress-domain.sh

    Please keep in mind that the script has to be run locally via SSH on the server where the database is actually located!.

    The script will first create a mysql database dump, before actually change anything in the current database.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search