Change Custom URLs without breaking old links

rdlugoszrdlugosz Registered Users Posts: 277 Major grins
Recently, I wanted to change my SM Custom URL without breaking all of the existing links out there that have been sent via email, etc. All you need is a little mod_rewrite action in either your httpd.conf or a .htaccess file...

Add this to httpd.conf:
<ifmodule mod_rewrite.c="">
<ifmodule mod_rewrite.c="">
RewriteEngine On

#Put your old domain in place of mine, the NC means "ignore case"
RewriteCond %{HTTP_HOST} ^photos.dlugosz.net [NC]

#Put your new URL here, 301 is the type of redirect to use;
# 301 is "permanent" and 302 is "temporary". The 'L' means
# that this is the Last rule.
RewriteRule ^(.*) http://gallery.rrdphoto.com$1 [R=301,L]
</ifmodule></IfModule>

Now, since you were using a DNS CNAME before, your webserver probably isn't looking for requests at this subdomain (if you're using a virtual host, which most people probably are). Just add the old host to the ServerAlias line in the httpd.conf:
ServerAlias dlugosz.net www.dlugosz.net photos.dlugosz.net
The next step is to actually change the DNS and the SM setup. Prior to doing this, I'd highly recommend setting the TTL values on your DNS entries pretty low so that you can quickly make fixes and not have to wait a day if you screw something up! Also, since SM will only respond to one custom DNS URL at a time, you'll need to get this transition over with quickly or for a while your links will be broken. Also, before doing this you should make sure that your new domain is set up properly with the CNAME entry pointing at user.smugmug.com. This URL won't actually work until you make the change on the SM config, but you want it ready to roll to minimize downtime.

You'll want to keep your old DNS entry as a CNAME, but change it's target from user.smugmug.com to your main webserver: mydomain.com. This way, requests will actually go to your webserver and not SM's. Now that this is setup, change your Custom DNS name in SM to your new URL: mynewdomain.com

If everything is done correctly, when a user goes to your old URL it'll actually make that request on *your* webserver, which will rewrite the URL into the new host name + whatever page was requested.

Check it out:
Base SM: http://photos.dlugosz.net

Specific gallery: http://photos.dlugosz.net/gallery/1466457</ifmodule>
Sign In or Register to comment.