ace’s blog

a place for me to record events in my life.

ace’s blog header image 2

Moved my blog to new domain

July 21st, 2006 · Comments · Tech News, Website

My blog used to be located at blog.petewood.us.  I just moved it to www.acedanger.com.  I had some decent search engine rankings on a few keywords and I didn’t want to lose them.  I knew there was a way to rewrite the URL so that if someone clicked on a link to one of my old pages, it would redirect them to the same page on the new domain.  For example, if someone clicked on a link to blog.petewood.us/2006/07/11/vacation/, I wanted them to be redirected to www.acedanger.com/2006/07/11/vacation/.  I have never written any scripts to rewrite URLs before so I turned to google for all the answers.  I found some info from several pages and came up with this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.petewood\.us
RewriteRule ^(.*)$ http://www.acedanger.com/$1 [r]

What this does is exactly what I have described in my example above.  I hope this helps someone out.  To test what I wrote, just click on the blog.petewood.us link above and it should take you to the acedanger.com page.

Tags:

  • Owen
    Hi ace,

    I am just wondering if you can share with me your entire .htaccess file and the corresponding httpd.conf settings?

    I recently moved my site from http://oblong.gotdns.org (a crappy DynDNS account) to http://owened.net -- my .htaccess file looks like so -- do you have any idea why its not working, the way it is? (save for the commented-out-until-its-working-properly lines)

    Thank-you.
  • Owen,
    I found the .htaccess file I have online. I must've looked at about 30 or 40 results of a google search until I figured out what was wrong with my htaccess file. Below is my entire .htaccess file on my old subdomain:

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^blog\.petewood\.us
    RewriteRule ^(.*)$ http://www.acedanger.com/$1 [r=301]

    Beyond showing you what I have, I am afraid that I can't be of any help figuring out why your file is not working just by looking at it. What is happening when you uncomment the commented lines?
  • Owen
    At present, the rules are:

    RewriteCond %{HTTP_HOST} !^owened\.net$
    RewriteRule ^(.*)$ http://owened.net/ [R,L]


    Which from my understanding means, "if the requested URL is not 'owened.net', then redirect the browser to 'owened.net' -- which works OK, except if for example someone were to browse to a page like http://oblong.gotdns.org/windowsxp-to-ubuntu-60..., they would simply be redirected to just owened.net.

    So now, my .htaccess looks like this:

    RewriteCond %{HTTP_HOST} ^oblong\.gotdns\.org$
    RewriteCond %{HTTP_HOST} ^www\.owened\.net$
    RewriteRule ^(.*)$ http://owened.net/$1 [R=301]


    Which says "if the requested URL is oblong.gotdns.org or www.owened.net, redirect the browser to owened.net" -- I think. The $ at the end of the RewriteCond lines means "remember what goes here", and the $1 at the end of the RewriteRule means "put what you remembered here", as far as I know...

    So, I've got no idea why it isnt working. :(
  • Owen, Try commenting out the second Rewrite Cond (RewriteCond %{HTTP_HOST} ^www\.owened\.net$). That appears to be the only thing that is different from my file and yours.
  • Owen
    Hi ace,

    It's been a while, but I finally got things working for me. Following are the relevant lines from my .htaccess:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^oblong\.gotdns.org$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.owened.net$ [NC]
    RewriteRule ^(.*)$ http://owened.net/$1 [L,R=301]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ http://owened.net/index.php/$1 [L]


    Some of them you will recognise from Wordpress' rules. The three important ones are lines 3, 4 and 8 -- a mate of mine helped me out, and we figured this.

    Anyway, just letting you know, and thanks again for your assistance. :-)
blog comments powered by Disqus