The easy way to change your domain name with a mutli-site setup

(2 minute read)

I used to dread changing the domain name of a site running Drupal in a multi-site setup. After changing the folder name all of my attached files would be broken, possibly some of my links would be broken and I would have to delve through thousands of records in the database to hopefully fix the broken files and links. Now I don’t dread it at all since I figured out I could get around all of these problems by using symbolic links.

Preface: Now for those of you who don’t know, symbolic links are a way to make a file or directory appear in multiple places while still referencing the same file[1]. The method I use requires symbolic links to work properly so you pretty much have to be hosting your site on some type of Unix system (FreeBSD, Linux, OS X, etc. Pretty much anything but Windows).

When I decided to move www.boaddrink.com to developerkarma.com the steps were easy. I first renamed my www.boaddrink.com directory to developerkarma.com[2]. After the directory was renamed I created a symbolic link with the name of www.boaddrink.com that pointed to developerkarma.com. This way when Drupal outputs the html pointing to the old www.boaddrink.com address the file system will pull the file from the real developerkarma.com directory. This even works for deleting old files so if I tell Drupal to delete an image file in the www.boaddrink.com/files directory the symbolic link redirects that request to actually delete the file from developerkarma.com/files.

Now that the filesystem is redirecting those bad requests, I’m now free to clean up the database at my leasure (and this might spawn a post at a later date :)

[1] http://en.wikipedia.org/wiki/Symbolic_link

[2] I rename my directories in a shell. Most low cost web hosts don’t allow you to have shell access so if you don’t have shell access try to rename your directory in your FTP client. If your FTP client wont let you rename a directory then I would recommend you download your directory to your local computer, rename the directory locally and upload the renamed directory (remember to chmod 777 your files directory).