Moving WordPress from a sub-domain to a sub-path

July 19th, 2018

Many years ago, it seemed a good idea to put the company blog to blog.itsth.com. Well, things have changed. SEO und https-certificates now make https://www.itsth.de/en/blog/ look better.

Here’s how to make the transition (assuming the data mentioned above):

  1. Add this to your .htaccess file:
    RewriteEngine on
    RewriteRule en/blog/(.*)$ /blog_rewrite.php?$1
  2. Create a file /blog_rewrite.php with this content:
    <?php
    
    function HandleAsRewrite($basepath, $blogurl)
    {
      $domain = strtolower($_SERVER['HTTP_HOST']); // "www.itsth.de"
      $scheme = strtolower($_SERVER['REQUEST_SCHEME']); // "https"
      $input = getenv("REQUEST_URI");
    
      if (substr($input, 0, strlen($basepath))==$basepath)
      {
        $page = file_get_contents($blogurl.substr($input, strlen($basepath)));
    
        $replacement = $scheme.'://'.$domain.$basepath;
        $page = str_replace($blogurl, $replacement, $page);
        $page = str_replace(str_replace('/', '\\/', $blogurl), str_replace('/', '\\/', $replacement), $page);
    
        foreach ($http_response_header as $headline)
          header ($headline);
    
        print $page;
    
        return(true);
      }
    
      return(false);
    }
    
    if (HandleAsRewrite('/en/blog/', 'http://blog.itsth.com/'))
      return;
    
    print "not found";
    
    ?>
  3. Optional: Edit the wordpress template’s header file and add:
    <link rel=”canonical” href=”https://www.itsth.de/en/blog<?php echo $_SERVER[‘REQUEST_URI’];?>”>

If you want to handle more than one blog, simply duplicate the “if (HandleAsRewrite” and the htaccess-entry.

Limitations: The script won’t handle POST data.

Finally an easy EULA

October 19th, 2017

End-user license agreements are always a terrible read.  Google has finally figured out how to do it better. They requested me to agree to the new terms. And that’s what they showed me:

Thanks, Google!

We never told you… Testing Facebook ads

September 27th, 2017

I’m currently trying to promote my new mobile augmented-reality-game. Which is a lot harder than I expected it to be. So I tried to advertise it. I published a post on Facebook with an animated GIF which reached 41 persons. Not much.

We never told you (Augmented reality)
We never told you: Youtube ⋅ iOS ⋅ Android

Then I invested $10 and tried promoting this post to people with interests that I selected. The results a pretty difficult to interpret. Facebook spreads the statistics over several places (in tiny windows) and basically avoids all industry standard terms. Instead they use terms that I can’t find definitions for. So I ‘reached’ 2.164 persons, but only 1.087 saw the video?

And some things don’t match at all. The average playing time was 4 seconds. With 1087 videos played, the total time should be around 72 minutes. But Facebook says it’s 171 minutes.

A lot of open questions. But what about the actual results? If you convert them to industry-standards, my results are:

  • CPM: 4,69$ / 9,20$ (persons/video plays)
  • CPC: 1,25$
  • CPA: -                  (meaning: no sales)

Not very good. Maybe this works better for other products or maybe I did something wrong, but I don’t think that I’ll continue this experiment… 😉

Fix: Breakpoints in wrong lines (=offset) in Visual Studio 2012

December 11th, 2015

Just had a very weird issue in VS2012 which cost me about an hour, so maybe this helps others.

When I placed breakpoints in a certain file, they more in fact displayed one line *below*. Sometimes even in blank lines. And often they didn’t work. This happened only in one file and only after a certain function. I tried a lot of things regarding the function, but that didn’t help.

It turned out that somehow the newlines codes for wrong here. If you look at the file in a hex editor, newline codes are normally:
OD 0A

At the problem location it was only:
0D

And that seemed to cause headaches to VS. Copying the entire text into an alternative editor and then back again fixed the file.

C++ weirdness

August 26th, 2014

 

I’m not sure if it’s an official C++ weirdness or just Microsoft’s version.

But this seems to be legal C++ code as I discovered by accident (=bug).

long x=0;
CString s = x[“test”];  // No compiler warning. Result is “t”

Posting requesting multiple products with inAppPurchaseManager

August 26th, 2013

Documentation for inAppPurchaseManager is poor at best. Here’s how to initialize with multiple products:
window.plugins.inAppPurchaseManager.requestProductsData([“myproduct1”, “myproduct2”, “myproduct3”], function(feedback)
{
for (var c=0; c<feedback[0].length; c++)
console.log(“Succeded: “+feedback[0][c][‘id’]);

for (var c=0; c<feedback[1].length; c++)
console.log(“Failed: “+feedback[1][c]);
});

inAppPurchaseManager and config.xml

August 26th, 2013

Just a short note because I found it nowhere else on the net:

If you’re getting this error:
ERROR: Plugin ‘InAppPurchaseManager’ not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.

You’ll need these magic words to integrate inAppPurchaseManager into your config.xml:
<feature name=”inAppPurchaseManager”>
<param name=”ios-package” value=”InAppPurchaseManager”/>
</feature>

Storing crash relevant information

June 22nd, 2013

Sometimes it’s helpful to store debug information on a regular basis somewhere and recover it if the program is crashed and restarted to get info about the cause of the crash. Unfortunately, there’s no perfect way for storing this data in Windows. And you don’t want to slow down your program to much. So I tried a benchmark and compared RegSetValueEx against SetFilePos(0) + WriteFile. (In both cases the handle was opened just once then used for writing 100.000 times.

And it turned out that WriteFile is 10x faster. More interesting facts:

– FILE_ATTRIBUTE_TEMPORARY didn’t change a thing.

– My SSD is fast (298ms), but my hard disk is faster (268ms, don’t ask me why) and my Ramdisk faster than both (206ms).

Dangerous MakeLower

May 2nd, 2013

Got weird crashes at customers with foreign languages? Microsoft’s MFC’s MakeLower could be the culprit. Seems to be poorly written because it can crash if it doesn’t like the string. I could even reproduce it here by switching the Windows-Locale for non-unicode apps the Japanese and process some strings contains German umlauts. Bottom-line? Don’t use, write your own… 🙁

Google correlates with county jail

March 21st, 2013

By accident I stumbled across a new Google trick called Google Correlate which looks for data that correlates with the search term that you enter. I didn’t really know what this is good for, so I just entered “Google”. And guess what: Google correlates with county jail.

Like all statistical data, it’s up to the reader to interpret it.

 

Google Correlate

Â