Recently I decided to change the URL for one of my websites, this website in fact! It used to be howtovideotutorial.org but I thought that was kind of long and I wanted a .com so I registered tutorialsave.com. Since I wanted to use the same platform (WordPress) and keep all of the content and comments etc. from before I set out performing the following steps.
To change the URL for your WordPress site there are two options, you can just change the URL or your can quickly duplicate the site content and associate the new copy with a new URL. This second approach is best because it ensures your site content won’t go down during the transition.
- Setup a new WordPress site using the new URL. For me this means creating a MySQL database, a folder for the new site, and entering the database username/password in the wp-config.php file. Then I upload all of the WordPress files to my server and run though the setup page.
- Once the new WordPress site is setup you need to determine your archive settings and everything else to prepare to import your content. This will be really easy if your old site is still online, you can just copy all of the settings from there.
- Now you need to copy over the files from the wp-content folder on your old site to the new one, this includes the plugins, themes and uploads folders.
- Go back into the new WordPress site and enable the theme and setup all of the plugins so that your new site matches the old one
- Now you just export your posts, comments and pages from the old WordPress website and import them into the new one. This is really pretty easy in WordPress, just go to Tools > Export and download the .xml file. In the new install just go to Tools > Import and choose that same .xml file, now all of the content will come in automatically
- The Import tool is great but in order to associate the image paths in your new site with the wp-content files you uploaded in step three you need to do a find and replace. A great plugin for this is the Find and Replacer, just search for any instances of “http://oldsite.com” and replace them with “http://newsite.com” where the URL’s match your old and new WordPress sites as shown in the image below
So now you’ve got a brand new WordPress site with all the right settings, all of the content, images and URL’s setup perfect! You’re practically done now but wait, there are really two WordPress sites online with the same content now. This is bad for search engines, they will see it as duplicate content and you will get penalized. What you need to do is use a 301 redirect from the old website to the new one to automatically redirect users and search engines.
In this case the only thing that changed is your URL, all of the file paths are the same and if you have incoming links or search engine traffic to http://oldsite.com/content you want it to be automatically rerouted to the same story on your new site at http://newsite.com/content
- On your old site, in the root directory find the file .htaccess and duplicate it. Name one copy htaccess-old.html and one htaccess.html
- I rename them as .html files because many editors have trouble figuring out how to open .htaccess files and edit them, some operating systems will even hide it because system files start with . and this appears to be a system file, renaming to .html will not hurt the file, it just makes it easier to work with temporarily
- Download htaccess.html and open it in any html editor, I use Dreamweaver, it should look something like the image below
- Delete all of the code you see in the htaccess.html file and replace it with the following two lines (where http://newsite.com is the url for your new site):
RewriteRule ^(.*) http://newsite.com/$1 [R=301,L]
- The first line activates mod rewrite, a system that routes http requests, the second line specifies a wildcard rule (.*) that means match everything and save it and then stick that same thing in at $1.
- So we’ve just told the system to take incoming requests for http://oldsite.com/anythinghere and replace them with http://newsite.com/anythinghere
- Now you just need to upload the htaccess.html file back to your old site root directory and rename it to .htaccess
- Everything should work! Try visiting a page on your old site by typing it into the URL, you should be automatically redirected to the new site. And if you ever want the old site back, just rename .htaccess to htaccess-redirect.html and rename htaccess-old.html to .htaccess and this will restore your old WordPress site
Good luck! I know this seems like a lot of steps but the whole thing can be done in just an hour or two and you’ll be off and running with a brand new URL for your WordPress site. If you want to hire me to run through these steps on your site just use the contact form here.