Skip to content

           

Moving WordPress to a New URL and New Permalink Structure

When I decided to change the permalink structure and move my WordPress blog from blog.raamdev.com to raamdev.com, I knew it was going to be a delicate process. I have over a thousand posts, more than three hundred of which have been indexed by Google. A huge portion of my traffic comes from Google, so my biggest concern was that the old URLs redirect to the new location.

Step 1: Disable plugins

It’s a good idea to disable your plugins before making these changes. At the very least, if you have a caching plugin installed (such as WP Super Cache), delete the cache and then disable that plugin.

Step 2: Change the blog URL

First, I had to change the WordPress blog URL from blog.raamdev.com to raamdev.com/blog/. This is simply a matter of updating the “WordPress address” and “Blog address” options from within the WordPress Administration panel (Settings -> General).

Second, I wanted the final URL to be raamdev.com/, instead of raamdev.com/blog/. To do this, I first changed the “Blog address” to raamdev.com/. Now to get WordPress working on the webroot (raamdev.com/), I had to move /blog/index.php to the webroot (/index.php) and then edit index.php and change this line,

require('./wp-blog-header.php');

to this,

require('./blog/wp-blog-header.php');

Now, when index.php is loaded, it knows to look for all the WordPress files in /blog/ and since WordPress has been configured to use raamdev.com/ as the “Blog address”, it will automatically handle everything else.

Step 3: Redirect old URLs to the new URL

The blog. sub-domain maps to a directory in the webroot called /blog/. If someone visits a link to a page that includes the sub-domain, the web server needs to tell the browser the new location. To do this, I needed to recreate the /blog/ directory and add the following to an .htaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.raamdev\.com$ [NC]
RewriteRule ^(.*)$ http://raamdev.com/blog/$1 [R=301,L]

Now, if someone tries to visit http://blog.raamdev.com/2010/01/28/some-blog-post, the web server will do a 301 redirect to http://raamdev.com/blog/2010/01/28/some-blog-post.

What’s a 301 redirect? Well, when you move a web page from one location to another, you can specify the type of redirection. A 301 redirect means the web page has been moved permanently. This is useful for keeping indexes updated. For example, if someone searches Google and finds an old link, Google will detect the 301 redirect and update its index with the new URL, thereby keeping your URL’s pagerank.

Step 4: Change Permalink structure

To change the permalink structure, I used the awesome Permalink Migration plugin by Dean Lee. With this plugin, I just specify the old permalink structure (in my case, this was /%year%/%monthnum%/%postname%/) and then change the permalink structure in WordPress (Settings -> Permalinks) to the new format (I’m using /%postname%/).

Now whenever someone visits a URL using the old permalink structure, Dean’s plugin sends a 301 redirect to the new URL.

Summary

With the .htaccess rewrite rule and Dean’s Permalink Migration plugin, we now have a double 301 redirect to make sure the old URLs redirect to the new ones:

  1. Someone searches Google and finds this link to my site: http://blog.raamdev.com/2010/01/28/some-blog-post
  2. The .htaccess rule rewrites the URL and redirects: http://raamdev.com/blog/2010/01/28/some-blog-post
  3. Dean’s Permalink Migration plugin redirects to the new permalink structure: http://raamdev.com/blog/some-blog-post

Posted in WordPress.

Tagged with , .


Mac OS X: Replicating md5sum Output Format

The md5sum program is used to calculate and verify 128-bit MD5 hashes. This program is installed by default in most Unix, Linux, and Unix-like operating systems including BSD. Mac OS X is a BSD variant and it also includes the md5sum program. However, the program is called md5 instead of md5sum and outputs an MD5 checksum in a different format than the standard md5sum program.

Here’s what the standard md5sum output looks like:

$ md5sum test.txt
d0ea20794ab78114230ba1ab167a22c2 test.txt

Now here’s what the output of md5 on Mac OS X looks like:

$ md5 test.txt
MD5 (test.txt) = d0ea20794ab78114230ba1ab167a22c2

While this normally wouldn’t be a big deal, it can cause major issues if you’re trying to run scripts that were written for a Unix-like environment which expect the default md5sum format.

Thankfully, md5 has a switch that reverses the output:

$ md5 -r test.txt
d0ea20794ab78114230ba1ab167a22c2 test.txt

If you’d like to permanently change md5’s behavior to mimic that of md5sum, you have two options:

The first is to simply add the following alias to ~/.profile:

alias md5sum='md5 -r'

Now when you type ‘md5sum test.txt‘, the command will be replaced with ‘md5 -r test.txt‘. However, this may not work with your scripts.

The second solution, and my preferred method, is to create a small script called md5sum that contains the following:

#!/bin/bash
/sbin/md5 -r "$@"

I then make this script executable (chmod +x md5sum) and put it in /sbin/. Now, whenever a script calls md5sum, the small bash script above is used and it produces output identical to that of md5sum on other Unix systems.

Posted in OS X.

Tagged with , , , .


PHP Session Permission Denied Errors with Sub-Domains and IE7 or IE8

I encountered a strange problem with IE7 and IE8 where if I visited example.com first and then visited sub-domain.example.com, Apache would return Permission Denied errors errors when trying to access the PHP session files for sub-domain.example.com.

After some investigation, it appears this is a problem with the way IE7 and IE8 request session data from Apache, or possibly because IE7 and IE8 have a non-standard way of announcing the domain they’re requesting session data for.

Here’s my scenario:

I’m running Apache 1.3 with two domains, each has their own account with their own users:

    Domain: mycompany.com
    Session path: /tmp/
    Webserver user: mycompanycom

    Domain: support.mycompany.com
    Session path: /tmp/
    Webserver user: nobody

Here is what happens during a normal visit with Firefox/Safari/Chrome:

  1. I visit mycompany.com and session file is created in /tmp/ owned by the user mycompanycom
  2. I then visit support.mycompany.com, and second session file is created in /tmp/ owned by user nobody
  3. Apache doesn’t get confused and the correct session files are returned

However, here’s what happens during a visit with IE7 and IE8:

  1. I visit mycompany.com and a session file is created in /tmp/ owned by the user mycompanycom
  2. I then visit support.mycompany.com and, instead of creating second session file in /tmp/ owned by the user nobody as you would expect (and as happens when using Firefox/Safari/Chrome), Apache tries to return the session file for mycompany.com.
  3. The session file for mycompany.com is owned by the user mycompanycom, so the web server, running as user nobody cannot access it. Permission is denied.

I searched Google for a solution and came across this question on StackOverflow. Several users suggested creating a separate directory in /tmp/ to separate the stored session data for support.mycompany.com from the session data for mycompany.com and then telling PHP to store all session data for support.mycompany.com in the new directory. This worked perfectly!

Here’s what I did. First, create the new session directory (Note: Make sure the new directory resides inside /tmp/!):

    mkdir /tmp/support.mycompany.com
    chown nobody:nobody /tmp/support.mycompany.com

I then added the following to an .htaccess file in the root web directory for support.mycompany.com:

    php_value session.save_path '/tmp/support.mycompany.com'

And finally, I removed all existing session data in /tmp/ to ensure the new session path would get used immediately:

    rm -f /tmp/sess_*

And that’s it! Now IE7 and IE8 work properly because when visiting support.mycompany.com, IE7 and IE8 do not accidentally find session data for mycompany.com and try to use it.

I’m fairly certain this problem has to do with how IE7 and IE8 request session data from Apache. They probably first request session data for mycompany.com and THEN request session data for support.mycompany.com, even though the latter was the only doman entered in the address bar.

Posted in Apache, Internet Explorer, PHP.

Tagged with , , , .


Removing the GMail “On Behalf Of” Sender Header

Like many of you, I have several email accounts and while using GMail as my primary email client would be nice, one of the things that has kept me from doing so is the annoying “On Behalf Of” that the GMail SMTP servers add to outgoing email. Some of the accounts are work related and the “On Behalf Of” comes across to me as unprofessional.

GMail On Behalf Of

That “On Behalf Of” part is caused by the Sender: header that GMail’s SMTP servers add:

Sender: my.personal@gmail.com
Date: Sun, 13 Dec 2009 10:33:18 -0500
Subject: Re: Project Details
From: raam.dev@mydomain.com
To: important-client@domain.com

Having your personal GMail address show up looks totally unprofessional and prevents you from being able to keep your personal email, uh, well, personal. Unfortunately, Google has already said it’s part of their SMTP server specs, so they won’t change it.

For a long time, your only option was to use a desktop email client like Outlook or Thunderbird to send email using your own domain’s SMTP server. However, this meant accessing your GMail account using IMAP/POP and basically defeated the purpose of the web client (unless you didn’t mind switching between the web and desktop client).

When Google offered GMail for Domains (now called Google Apps for Domains), I eagerly set up a free account using one of my domains and tested to see if email sent still included the Sender header. Sadly it did and I abandoned the idea of using GMail as my primary email client.

A few days ago I accidentally discovered that now both the standard GMail and Google Apps for Domains have the ability to specify your own SMTP server when you add an external email address to your GMail account. (Here’s the announcement from a few months ago on Google’s Blog.) This means you can receive email from you@yourdomain.com and also reply to emails from within GMail as you@yourdomain.com and the receiver won’t know that you’re using GMail!

Here’s how to get this set up:

Login to GMail and click Settings at the top right. Then click the Accounts and Import tab:

GMail Settings - Accounts and Import

Now make sure the “Reply from the same address the message was sent to” is selected and click “Send mail from another address” to add your external email account.

GMail - Send mail from another address

Fill in the name you want to show up when you send email from this account. This will probably be your name, but it might also be something like “Company Support” or “Sales”. Now enter your full external email address in the second box and then click Next Step.

GMail - Add another address - Step 1

On the next screen, select the second option box, “Send through SMTP servers” and fill in the SMTP Server, Username, and Password fields. When you click Add Account, Google will try connecting to the SMTP server using the credentials you supplied. If it successfully connects, you’ll be brought back to the Accounts and Import tab with your new account added. Otherwise, Google will display the error it had when trying to verify the SMTP connection details.

GMail - Add another address - Step 2

Now you should see the new account listed on the Accounts and Import tab, along with a note at the bottom showing that email will be sent using the SMTP server you specified:

GMail - New account listed on Accounts and Import tab

Now, you can send and receive email using this external account and the receiver won’t see that annoying “On Behalf Of” message! Your GMail address won’t even be visible in the email headers if they choose to view the email source (they’ll see that the email was routed through a Google server, but Google is well known enough that they probably won’t care).

Posted in Google.

Tagged with , , .


Mac OS X: Fixing ‘Always Open With’

After installing the TextMate editor I wanted all shell scripts (files ending with the .sh extension) to open in TextMate. Unfortunately, selecting Open With -> Other… from the context menu, choosing an application, and then clicking the Always Open With checkbox doesn’t change the default application for all files with that extension, but rather only changes that specific file.

If you want to change the default application used to open all files with a specific extension, the steps are slightly different:

Select the file and choose File -> Get Info (or Cmd+i) and expand the Open With section:

Get Info

From here, select the application you want to use for opening those file types and then click Change All. This will update the OS X Launch Services Database, which is consulted when opening files. Now all files with that extension will be opened with the application you selected.

Posted in OS X.

Tagged with , , .