Change Your WordPress URL

2328879637_c0d2e376ff

If you ever need to change the URL for your WordPress installation, this quick tip will help you. I just recently went through this process with another blog and while it was relatively painless, it could have been disastrous.  Make sure you backup before beginning.

Changing your WordPress URL from www.oldwebsite.com to www.newwebsite.com is very simple if you follow these steps.

Important: Backup your database before proceeding.  I made a mistake and screwed up my installation, but luckily I had a backup to restore.

Step 1:
If you didn’t read the note above, backup your database!

Step 2:
Change the WordPress and Blog URL in the Settings -> General section of your administration panel.

Step 3:

Step 3a:

If you are changing the directory of your blog and it is staying on the same domain, modify your .htaccess file at the root of your blog.  Here is the block of code to change:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /webrealignment/  <– update with new directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /webrealignment/index.php [L] <– update with new directory
</IfModule>

Step 3b:
If you are moving your blog to a new domain, make sure to copy the custom redirects from your original .htaccess file and ensure that they reflect the new URL.

Step 4:
Modify your GUID field in the database.  The GUID are unique values for each item (usually a URL).  Go into phpMyAdmin and click on the SQL button.  Execute the following code (make sure that you replace the URLs for your own old/new URLs):

UPDATE wp_posts SET guid = REPLACE (
guid,
'http://exampleoldsiteurl.com',
'http://examplenewsiteurl.com');

Step 5:
At this point your site will work fine, but the images will be broken in your posts.  While you are still in phpMyAdmin, execute the following SQL code to update your blog posts to reflect the correct referencing for images:

UPDATE wp_posts SET post_content = REPLACE (
post_content,
'http://exampleoldsiteurl.com',
'http://examplenewsiteurl.com');

Step 6 (this is only required if you are switching directories on the same domain):
Modify your upload path by going to Settings -> Miscellaneous and change the ‘Store uploads in this folder’ field to reflect the new directory.

Step 7:
Test your installation.  Ensure the links, image, plugins, etc. are working.

Reblog this post [with Zemanta]