Top SEM and SEO Tips    

WordPress Returns ‘Unknown Host’

January 16, 2012 – 3:20 pm

I wanted to park one of my domains on top of another and use the canonical feature of WordPress to redirect the inbound link equity from the one domain to the other domain however when setup the second domain always returned ‘Unknown host: xxxx.com’.

I know if this is default behavior however I had so many plugins on this server it is often hard to tell what comes from WordPress core and what comes from plugins. As this is a live site I didn’t want to turn off all plugins until I found the one creating the issue.

My solution was to use a .htaccess 301 redirect from one hostname to the other. This redirect happens before WordPress gets involved so all WordPress sees is the domain it thinks its running on.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.topsemtips\.com$
RewriteRule (.*) http://www.topsemtips.com/$1 [R=301,L]

This will redirect all requests to the domain www.topsemtips.com that do not use that as the host name (they might use topsemtips.com or xyz.com) to the same URL with the host name changed to www.topsemtips.com.


Google likes to push its own products

January 12, 2012 – 3:34 pm

Can’t stand this personalization kick they’ve been going on – the results I got back from one recent search where totally skewed in a way I didn’t want and didn’t ask for:

They know I shared the URLs so if Google wants to implement personalization they obviously don’t need me to join Google+ – this appears to be leveraging one product to hawk another which is what Microsoft kept doing (and kept getting fined for doing) with their Internet Explorer product. Hopefully Google will get investigated and fined – as they should be for this blatantly anti-competitive behavior by a monopoly in the search market.


WordPress Theme Scanning

January 12, 2012 – 3:18 pm

Noticed on one of our clients someone was trying to scan the theme directory looking for style.css files that might exist. I would imagine this is to find themes installed, and their version numbers which would then allow the person scanning to use a known exploit to break into a WordPress installation.

I caught this because I have the ‘Redirection’ plugin installed and set to log all accesses that result in a 404 error – usually I use this to put in redirects to stop the visitor getting a ‘page not found’ message. In this instance it has helped highlight someone trying to hack the site.

Sample redirection log:

Jan 7, 2012 ​/wp-content​/themes​/vibrantcms​/style.css 62.205.150.221
Jan 7, 2012 ​/wp-content​/themes​/thick​/style.css 94.244.60.171
Jan 7, 2012 ​/wp-content​/themes​/therapy​/style.css 117.203.9.147
Jan 7, 2012 ​/wp-content​/themes​/thejournal​/style.css 46.180.211.171
Jan 7, 2012 ​/wp-content​/themes​/suitandtie​/style.css 114.25.38.108
Jan 7, 2012 ​/wp-content​/themes​/sophisticatedfolio​/style.css 178.125.206.36
Jan 7, 2012 ​/wp-content​/themes​/slanted​/style.css 188.112.247.128
Jan 7, 2012 ​/wp-content​/themes​/royalle​/style.css 41.189.48.151
Jan 7, 2012 ​/wp-content​/themes​/retreat​/style.css 213.88.102.151

So to stop this I:

  • Installed ‘Bad Behavior’ plugin – this knows ways people try to hack your system and blocks them. Not sure if it would catch this scan attack but it catches other scanners so is always good to install.
  • Remove unnecessary themes. I always leave the current theme and one of the WordPress installed themes (Twenty Ten/Twenty Eleven) – this way if the main theme breaks for some reason there’s always a fallback theme and I know these two themes are supported and maintained by WordPress. All other themes including the earlier WordPress themes 1.5 and 1.6 are removed.

Unable to post message to http://googleads.g.doubleclick.net. Recipient has origin xxxx

December 28, 2011 – 2:24 am

Had this issue on one site when running Chrome and after much hunting did not find a documented solution. However I did manage to find and correct the issue after a little playing with my code.

The issue ended up being a totally unrelated

tag with a float left (it was a div around the breadcrumbs). This tag was used on other pages with ads with no issues, just one page had this problem. Unfortunately it was the template for the main part of the site so the ‘unable to post message’ issue had to be fixed.

To track down if a ‘float left’ is the cause of your problem try removing all CSS style sheets and see if the ads now start working. If the Google ads do start working then you just need to add in parts of the CSS and retest until you narrow down the code that’s causing the issue.

In my code I was able to change the float left to a ‘text-align:left;’, the ads kept displaying and my look/feel was left intact.


WordPress How To Convert Tables to Innodb

December 15, 2011 – 6:12 pm

Innodb tables are tables within MySQL that should be used instead of MyISAM for numerous reasons, the very least is that their transactional nature means they will not corrupt if you system has to reboot or lose power.

One of the problems is to change your tables from MyISAM to Innodb you need to run the following command:
ALTER TABLE YourDB.wp_posts ENGINE=InnoDB;
Once per table and that means lots of manual typing

I found a script that will create the list of tables for you:
SELECT CONCAT( 'ALTER TABLE `', table_schema, '`.`', table_name, '` ENGINE=InnoDB;' )
FROM information_schema.tables
WHERE ENGINE = 'MyISAM'
AND table_schema NOT
IN (
'information_schema', 'mysql'
)

Which outputs something like:
ALTER TABLE YourDB.wp_bad_behavior ENGINE=InnoDB;
ALTER TABLE YourDB.wp_commentmeta ENGINE=InnoDB;
ALTER TABLE YourDB.wp_comments ENGINE=InnoDB;
ALTER TABLE YourDB.wp_links ENGINE=InnoDB;
ALTER TABLE YourDB.wp_options ENGINE=InnoDB;

Which you can then cut and paste into any MySQL SQL window and run and all your tables are converted. The nice thing is if the script stops for some reason you can rerun the first script again without breaking anything.

Note – if you see ‘….’ at the end of the ‘ALTER TABLE’ lines this is phpMyAdmin truncating the output – turn on full text output and you’ll see the correct commans.


DropBox High I/O Issue

December 2, 2011 – 11:12 am

DropBox is a miracle, allowing you to share files and keeping all your files up to date without the need to install a file server. This problem happened when I tried to install DropBox on a Windows Vista laptop – an old Dell Inspiration 620. The symptoms reported by the user were slow application response times since DropBox was installed.

I had a look and the machine had a few gigs of disk space but DropBox was stuck reporting ‘Downloading 10 files….’ though it never seemed to do anything.

I had a look at the Resource Monitor application and sure enough DropBox had really high read/writes and the hard disk was running at 100%.

We decided to clean up some disk space and managed to free 9GB by deleting an old installation of Google Desktop. Within minutes the 9GB had disappeared.

It seemed that DropBox was downloading files and trying to write them to the disk but was failing due to a low disk space threshold within the application (there was at least some disk space left on the device so it wasn’t a physical limit). Given the laptop only had 110GB disk I turned on FileCompression which freed up another 10GB before I left for the day. When I came in DropBox had gone to its usual low disk I/O state, hard drive had 3GB free and the system was responsive again.


Reasons I did not renew with Inmotion Hosting

November 4, 2011 – 12:48 pm

Just received a invoice payment chaser from Inmotion Hosting. Thought I would share with you why I am not using their service anymore:

We moved off your servers months ago due to having the service turned off randomly, god awful support, and when we complained to your quality assurance department they said that your service was just fine. Well it wasn’t, we’re not on you anymore, and we’re not recommending you to anyone anymore.

While realizing we’re a small fish for you we were much bigger having multiple hosting accounts, a dedicated server and two VPS servers. We used your services for years. All our hosting needs are now off your servers. We moved the dedicated server to Amazon and now have 8 servers with them so you should consider your appalling service has cost you circa $3,000 per month plus any referrals we might have given you.

Turning off someone’s service is not acceptable, it costs money and hurts reputations. You might accuse people of abusing your service due to temporary load but turning off service makes me look bad in front of my bosses and I won’t stand for that.

Dylan


Convert WordPress Comments Form into a Table

November 2, 2011 – 4:00 pm

If you’re fed up with your comment form fields not lining up properly here’s how to turn the form fields into a table which you can then use CSS to format.

In your theme’s functions.php file add the following code:

<php
add_action( 'comment_form_before_fields', 'uniquename_comment_form_before_fields' );
function uniquename_comment_form_before_fields() {
      echo '<table id="PostCommentTable">';
}
add_action( 'comment_form', 'uniquename_comment_form' );
function uniquename_comment_form() {
      echo '</td></tr></table>';
}
?>

Then in your comments.php file locate the line that reads ‘comment_form()’ and replace with the following:

<?php
$comment_args = array( 'fields' => apply_filters( 'comment_form_default_fields', array(
       'author' => '<tr><td>' .
       '<label for="author">' . __( 'Your Name' ) . '</label> ' .
       ( $req ? '<span>*</span>' : '' ) .
       '</td><td><input id="author" name="author" type="text" value="' .
       esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' .
       '</td></tr><!-- #form-section-author .form-section -->',
       'email'  => '<tr><td>' .
       '<label for="email">' . __( 'Your Email' ) . '</label> ' .
       ( $req ? '<span>*</span>' : '' ) .
       '</td><td><input id="email" name="email" type="text" value="' . esc_attr(         $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />' .
       '</td></tr><!-- #form-section-email .form-section -->',
       'url'    => '' ) ),
       'comment_field' => '<tr><td>' .
       '<label for="comment">' . __( 'Let us know what you have to say:' ) . '</label></td>' .
       '<td><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
       '</td></tr><!-- #form-section-comment .form-section -->',
       'comment_notes_after' => '<tr><td>&nbsp;</td><td>',
);
comment_form($comment_args);
?>

This will then turn your comment form into a table with the id of PostCommentTable. Then simply add some CSS into your styles.css file (also in your theme directory):

#PostCommentTable td {
vertical-align:top;
padding:2px;
}
#PostCommentTable tr td:first-child {
text-align:right;
padding-top:8px;
}

And you end up with a really nice looking comment table


Steps to Move eCommerce Store to New Domain Name

October 6, 2011 – 5:00 pm

Before you move the store:

  • Check that the cart will handle the change in domain names, nothing is hard coded to the current domain, no license restrictions, etc.
  • Check your host allows parked domains.
  • You will need to obtain a SSL certificate for the new store so your checkout continues to work.
  • Does your site enforce one domain? If so can you change to the new domain name?
  • Check none of the coded pages refers directly to the old domain name– the only time it should be hard coded is the jump to the secure checkout. If there are pages with the domain in them you will need to edit to remove the domain name or list them for change after the conversion.

The issue is the SSL certificate, a host will only respond to one at a time (a limitation of the HTTPS protocol means the certificate is attached to one IP address so two certificates would require two IP addresses) so when you decide to make the switch you will need to install the new SSL certificate and then make your store respond to the new address. Overall downtime should be minimal as both addresses will resolve but there is going to be some delay switching SSL certificates.

Rough list of steps involved in the move:

  • Modify the DNS record for the new domain to point to the IP address of the current site
  • You will need to park the new domain on top of the old domain. Usually your host control panel will allow you to set up the current hosting to respond to both domain names.
  • Once both domains resolve you will be able to make the switch.
  •  Change the store to respond to the new domain name
  • Install the SSL certificate
  • Modify any remaining on page mentions of the old domain name to the new domain name
  • Test.

PHP and Memcached Returning Random Data

September 15, 2011 – 12:45 am

This took a long time to track down and only applies in specific circumstances:

  • Your process is forking
  • You are using persistent memcache connections
  • The data you request does not match what you receive, for instance you expect an array and an integer is returned.

The problem is caused by the persistent connection being shared after the process has forked. This is a known issue on database connections which is why you should always stop and restart your database connections after a process forks however this is not a documented ‘feature’ of the memcache connections. Trying to close and reopen the memcache connections doesn’t help either. What is happening is two processes are using the same pipe to talk to memcache, they both request data at roughly the same time however the responses go back to the wrong processes, so process A gets the data meant for B, and process B gets process A’s data.

The best approach I’ve found to this issue so far is:

  • Mark the data stored with the key it was stored under.
  • When the data is returned check the key returned to ensure its the same as the key requested.
  • If there is a mismatch treat it as a cache miss – return false.

This increases your cache misses however it ensures your application works as you coded. Its a simple change, instead of storing the just the data, you add an additional parameter to indicate the key the data was stored under:

Instead of:

function CacheAdd( $Key, $Data , $TTL ){
    // add code to create your memcache connection
    $memcache->add( $Key, $Data , false, $TTL );
}

You use:

function CacheAdd( $Key, $Data , $TTL ){
    // add code to create your memcache connection
    $DataToStore = array( 'Key'=>$Key, 'Data'=>$Data ) ;
    $memcache->add( $Key, $DataToStore , false, $TTL );
}

and then when you retrieve:

function CacheGet($Key){
    // add code to create your memcache connection
    $DataFromStore = $memcahe->get( $Key );
    if ( !isset($DataFromStore['Key']) || $DataFromStore['Key'] != $Key ) {
        return false;
    }
    return $DataFromStore['Data'];
}