Quick snippet to change all instances of WordPress URL

Sometimes you are moving a websites folder structure, or sometimes you are moving a website hosts. This quick and easy sql script will allow you to update all instances of the current URL with a new URL so moving wordpress sites is painless.


UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

WordPress SSL Offloading

Understanding what’s happening

When your page is accessed over HTTPS, but the Load Balancer is performing SSL offloading and actually requesting your content on the non-SSL port 80, the webserver, PHP, or anything else for that matter, does not understand or see that it’s being accessed over https://.

The fix for this, is that Load Balancer sends the de-facto standard X-Forwareded-Proto HTTP header, which we can use to figure out which protocol the client is actually using on the other side of the Load Balancer.

With Apache 2.2, you could use something along the lines of:

<IfModule mod_setenvif.c>

SetEnvIf X-Forwarded-Proto “^https$” HTTPS


This simply reads the X-Forwared-Proto header, and if it equals https then, sets the HTTPS environment variable to 1. PHP will see this environment variable, and eventually it will become $_SERVER[‘HTTPS’] that equals 1 — just like it would be for a “real” native SSL request.

The solution

Websites behind load balancers or reverse proxies that support HTTP_X_FORWARDED_PROTO can be fixed by adding the following code to the wp-config.php file

if ($_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’)


Then to redirect any http requests to https, we need to define the following In the .htaccess file:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} !https

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteBase /

RewriteRule ^index\.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]



The important parts here are in bold. Under usual circumstances inside the .htaccess file the rewrite condition would be to check for https to be set to OFF:

RewriteCond %{HTTPS} off

When behind some forms of proxying, whereby the client is connecting via HTTPS to a proxy, load balancer, Passenger application, etc., the %{HTTPS} variable may never be on and cause a rewrite loop. This is because your application is actually receiving plain HTTP traffic even though the client and the proxy/load balancer are using HTTPS. In these cases, check the X-Forwarded-Proto header.




Hiding Applications from the Mac Osx Dock

I have a few applications that I run whilst I’m using my computer, these applications are literally only used upon startup and then never touched again until I need to restart my computer.

What’s the point in having them in the system dock? Well, none. Usually you can do a simple right click on the application and then hide from dock. Though some programs are stubborn don’t like to behave as they should.

The way you can avoid all aggravation with these programs and get them to hide forcefully is to edit the applications info.plist.

To find this file, navigation to where your application resides, usually in the applications folder within OSX. Once there find the application.app and right click and hit “Show Package Contents”.

This will take you to a new folder and within here you should be able to see a info.plist. This is a small xml file in Apple’s Property List XML format. It’s contents is a key pair value structured file that contains a few default rules. Apple states the file to be:

“Launch Services (part of the Core Services framework in OS X) provides support for launching apps and matching document types to apps. As a result, the keys recognized by Launch Services allow you to specify the desired execution environment for your bundled code. (In iOS, Launch Services is a private API but is still used internally to coordinate the execution environment of iOS apps.)”

Here we can specific whether or not to show it in the dock bar.

Open the file with a text editor, I suggest Sublime Text, once opened do a quick find for “LSUIElement” – if found we just need to add a value true, to this element. However if “LSUIElement” doesn’t exist we can simply add the following at the bottom of the file before the ending </dict> </plist> –