• Hi there,

    I moved my travel blog (blog.kait.us) from Blogger to self-hosted WordPress on Monday. I had done a practice run on a different sub-domain and it all went quite swimmingly.

    I changed the permalinks structure to mimic the Blogger /year/mo/name format, and I had thought my links would be fine. But I didn’t notice that there was a slight different.

    Old / BLogger URL
    https://blog.kait.us/2011/05/international-cell-phone-forwarding.html

    New / WordPress URL
    https://blog.kait.us/2011/05/international-cell-phone-forwarding/

    I get a little traffic from google searches, particularly for specific places I’ve been and written about. The google results always link to the old format URL, resulting in the viewer getting a “Not Found” error.

    Now, my PHP is a little rusty and I have never had much need to dive too deep into the WordPress code, so I wanted to ask some advice.

    I *think* that I want to add some redirect code *somewhere* so that a user who arrives at blog.kait.us/nnnn/nn/ssssssss.html will get forwarded to blog.kait.us/nnnn/nn/ssssssss rather than shown a “Not Found” page.

    Does that sound right? And perhaps, does anyone have an idea about where I would put that code or even better, know a tutorial I could follow? I know I’m not the first to move from Blogger to WP.

    I DO TRULY apologize if this is something I should be ably to find out on my own. My searches so far have been dominated by people who want to redirect their old domain to their new one, and I (special snowflake that I view myself as) think this is a different type of problem. I have always used the same URL (blog.kait.us) both when Blogger hosted/powered my blog and now that Dreamhost/Wordpress do.

    Many thanks for any info you could throw my way!
    –Kait

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello kaitlyn_, re ‘The google results always link to the old format URL’, I would recommend an excellent plugin called Google XML Sitemaps –

    This plugin will generate a special XML sitemap which will help search engines like Google, Yahoo, Bing and Ask.com to better index your blog

    You can find it here.

    Thread Starter kaitlyn_

    (@kaitlyn_)

    Thanks obi-wan-kenobi! I’m going to install that plug-in, as the ideal is for google to link right to the new URLs.

    Since that still doesn’t solve the problem of anyone who comes across an old-style URL getting the 404. Most people, even tech people, when they see ‘page not found’ will assume the content is gone before url hacking.

    So what I did was track down the file that makes that “page not found” page. It turns out it lives here:

    blog.kait.us/wp-directory/wp-content/themes/my-theme/404.php

    Since, my PHP is a bit rusty, I just wrote up some Javascript wrapped in a <script> tag and pasted it into the 404.php file.

    I made a big array of all my old and the corresponding new URLs. Perhaps not the cleanest idea, but since there is a set number of posts that were written before I moved to WordPress and that set is not changing, seems good enough. My script goes through that list, comparing each of the ‘old’ urls to the current url of the page, if there’s a match then it redirects me to the corresponding new page.

    This only gets executed when a reader gets the 404 / Page Not Found error. I would still be interested if anyone had any feedback or thoughts of a better way to accomplish this.

    cheers!
    –Kait

    <script>
    
    function redirectFromBloggerURL() {
    
    var bloggerTable = [
    ["https://blog.kait.us/2014/07/stella-cat.html",
    "https://blog.kait.us/2014/07/stella-the-cat/"],
    ["https://blog.kait.us/2014/06/ravenna.html",
    "https://blog.kait.us/2014/06/ravenna/"],
    ["https://blog.kait.us/2014/06/hiking-dolomites.html",
    "https://blog.kait.us/2014/06/hiking-in-the-dolomites/"],
    ["https://blog.kait.us/2014/06/visiting-veneto.html",
    "https://blog.kait.us/2014/06/visiting-emanuele-and-silvia-in-veneto/"]
    ];
    
    var currentURL = document.URL;
    
    var wantedURL = '';
    
    for(var i = 0; i < bloggerTable.length; i++) {
    	currentKeyVal = bloggerTable[i];
    	if (currentURL == currentKeyVal[0]) {
    		wantedURL = currentKeyVal[1];
    		break;
    	}
    }
    
    if (wantedURL != '') {
    	window.location = wantedURL;
    }
    }
    
    redirectFromBloggerURL();
    
    </script>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirecting "/foo-post.html" to "/foo-post/" after moving blog’ is closed to new replies.