Thursday, September 24, 2009

How to move your WordPress blog to a new domain (the easy way)

Whether you're moving a WordPress blog to a new domain or moving a new blog from staging to live, it could be problematic especially if you don't like mucking around with the database. Here's an easy way to move your blog just by editing wp-config.php and using the Velvet Blues Update URLs plugin.

Edit wp-config.php, add the following lines at the beginning of the file (where "" is the NEW location of your site):

After editing wp-config.php, you will be able to access your new blog's admin on the new domain, but images and links that are on your blog posts will still be pointing to your old domain. To fix this, download and install the Velvet Blues Update URLs plugin. Go to Settings-> Update Urls, select "Update urls AND links in page or post content: YES", enter your old URL and your new URL, and click Update URLs.

..and you're done! :)

Wednesday, September 16, 2009

CakePHP Tip: Creating https:// links

It's always better to use CakePHP's HTML helper to create relative links that will make your app portable. What if you need to create relative link that will use https:// instead of the default http://? This will be useful if most of your site uses http:// but some pages need to be secure (eg. registration or checkout page). Let's say your link is pointing to /pages/register, here's how to do it:
echo $html->link("Register", str_replace('http://', 'https://',
$html->url("/pages/register", true)));

What happens here? we use $html->url() to create a relative URL, and set the 2nd parameter to true so it will return the full URL (eg. and then replace http:// with https://, we then pass that URL to HTML helper's link() method to create a HTML link.

Note that you don't need to do this if the originating page is already using https://. If that is the case, then all relative links will also use https:// by default.