Redirect WWW to non-WWW using Apache (htaccess)

The easiest way to redirect all your traffic from a WWW address (like to a non-WWW (like is using the following code:

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

With this code, you don’t need to hard-code the name of the domain into the .htaccess file.

Apart from the fact that www is deprecated (more here), the main benefit of doing this (or redirect from non-WWW to WWW) is that Google and other search engines won’t penalize our site because of duplicated content on both versions of our domain (WWW and non-WWW).

Recursively copy from a FTP server

In Linux (and also in the World of Windows), there is a small great tool called wget (you probably already know it, it’s pretty popular). I have been using it for some years know as it is very convenient for downloading files (or even entire HTML websites) from the command line (specially when you manage a Linux server through SSH). What I didn’t know about it was that it also allows you to recursively copy files from a FTP server (a task that is not usually pleasant).

This is how:

wget -r*

If the FTP username is something like this:, then, you should replace the @ by a + simbol, like this:

Nginx newest version on Ubuntu Lucid 10.04 LTS

Some time ago I wrote a post regarding this same topic (installing an updated version of Nginx instead of the one that is on the official Ubuntu repositories) but for Hardy (8.04).

Now, it is the turn of the latest Long-Term-Support version of this Linux distribution.

In this case, we need to use this repository:

deb lucid main

You can create a file like /etc/apt/sources.list.d/nginx-stable.list, and put that line inside.

We also need to add the key of this repository so Ubuntu won’t complain.

apt-key adv --keyserver --recv-keys 00A6F0A3C300EE8C

and finally, run:

apt-get upgrade && apt-get install nginx

Windows 7 failing to copy large files through network

I have faced problems copying large files (several hundreds megs) over a Windows Network between two Windows 7 boxes. During the copy, the process just freeze forever, and when trying to cancel it, it just tries forever without success.

At first I tough it was a antivirus/firewall issue, but disabling the software on both machines didn’t fix the problem. What really helped was this fix, that disables a feature called Auto-Tuning. It only takes one command on the Command Prompt (Start/Run: cmd) to bring it down:

netsh int tcp set global autotuninglevel=disabled

Then, restart the machine and voila, the problem should be gone.

If this does not fix your problem and want to re-enable this feature, just run:

netsh int tcp set global autotuninglevel=normal

Two ways to check if a Registry Key exists using VBScript

The first one is using the method RegRead from WScript.Shell.

If the given key is not found, it will rise an error, so we need to use an On Error Resume Next (which I don’t really like).

We would need to pass to the function a string like HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ (note the trailing \) if we are looking for a Registry Key (those that look like a folder). If we want to check if a value inside a key exists, we would remove the trailing \, like HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\CurrentLevel.

Function RegKeyExists(Key)
  Dim oShell, entry
  On Error Resume Next
  Set oShell = CreateObject("WScript.Shell")
  entry = oShell.RegRead(Key)
  If Err.Number <> 0 Then
    RegKeyExists = False
    RegKeyExists = True
  End If
End Function

The second method uses WMI.

In this case, we would need to pass the Key Hive (Current User, Local Machine, etc) in the form of hex numbers (I declared them as constants). The KeyPath would be something like SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings.

Const HKCR = &H80000000 'HKEY_CLASSES_ROOT
Const HKCU = &H80000001 'HKEY_CURRENT_USER
Const HKUS = &H80000003 'HKEY_USERS

Function KeyExists(Key, KeyPath)
  Dim oReg: Set oReg = GetObject("winmgmts:!root/default:StdRegProv")
  If oReg.EnumKey(Key, KeyPath, arrSubKeys) = 0 Then
    KeyExists = True
    KeyExists = False

The difference with this function is that will only check for Registry Keys and not for values.

Android FAQ – HBOOT and rooting

I found this information on AndroidForums and it is very helpful, so just wanted to keep it (maybe it helps someone else also):

What’s HBOOT?
It’s immediately loaded when the phone is switched on. It’s mostly responsible for checking and initialising the hardware and starting the phone’s software, for flashing official software releases (RUUs via Fastboot), as well as a few other things. In some ways it’s comparable to the BIOS on a PC.

How do I root HBOOT?
You can’t, it makes no sense. It’s a bootloader, not Android. It’s like trying to play a DVD on your kettle.

What does upgrading HBOOT do?
It may add extra hardware support for new phones (e.g. SLCD displays) and may fix a few bugs. HTC doesn’t release information about it.

What does downgrading HBOOT do?
The opposite. So, if you flash an SLCD phone with an old version of HBOOT that doesn’t have the support, the screen won’t work.

But rooting depends on HBOOT version?
It doesn’t.

Why does upgrading HBOOT remove root?
It doesn’t. When you flash an official update your ROM is replaced with an official one, which is why root is lost.

How do I change HBOOT version?
By installing an official RUU/update. There’s no other way – the bootloader is protected by the phone’s hardware security because a corrupt bootloader means a bricked phone with no way to recover. RUUs contain a version of the bootloader, which is automatically flashed.

Why do I need to downgrade HBOOT to root 0.92?
You don’t. You had to downgrade Android because unrevoked3 couldn’t root froyo. The new release can, so it works.

Why all the talk about HBOOT then?
Because it is confused with software release, which is the important part. An RUU won’t work if the installed software is a higher version (e.g. 1.20.x won’t work if you have 1.21.x), and people have mistaken that check for HBOOT version.

What about the xda 0.92 to 0.80 downgrade? It runs on froyo.
It’s an engineering/test release from HTC that was leaked. It fakes its software version to 2.09.405.8 so it will run on froyo and downgrade the ROM, so long as you’re not on a higher release than that. The process has nothing to do with HBOOT, but it does downgrade the bootloader to 0.80 as a side effect – and results in a dead screen on SLCD phones. It’s generally a bad idea to use this hack.

Why would any of this matter?
Because instructions based only on HBOOT version are not reliable. They may not work, or may cause your phone to stop working.

Definition: Recovery
A very small operating system on the phone, totally separate from Android, that is used to update your phone’s existing software via OTA updates, and has extra security privileges. When you permanently root your phone you also replace this with a different version (‘custom recovery’) that will allow you to install custom ROMs and not just official HTC updates.

Definition: ROM
Usually refers to the boot image and the system image (the kernel and Android), but broadly refers to all of the phone’s software. A custom ROM is anything that is modified from stock HTC. Custom ROMs you download can only be installed in recovery.

Defintion: RUU
Rom Upgrade Utility. HTC’s official way of flashing the phone’s software (i.e. completely replacing it, not updating existing software). An RUU can get past the phone’s security, and can change parts that you normally can’t even when rooted, e.g. the splash screens, the bootloader. An RUU wipes everything off the phone and is like a ‘total’ factory reset. That’s why it can be used to debrand or rebrand a phone.


From: AndroidForums

Install updated version of nginx on Ubuntu Hardy 8.04LTS

Nginx is a great web server to handle tons of traffic with relative low resources, it beats Apache big time.

I have started using  it as a Reverse Proxy, Load Balancer, Web Cache and static files web server (like images, javascript and CSS) in front of Apache (for PHP processing). I’m more than amazed with the results.

The problem is that Ubuntu Hardy 8.04 comes with Nginx version 0.5 (version 1.0 has been recently released), and lacks of some features as Cache. An easy way to update the version to a more recent one (currently, to 0.8) without upgrading the whole Ubuntu version is using the following PPA repository:

To add this repository to your system, you need to create a file inside /etc/apt/sources.list.d/ (for instance, nginx-stable.list) with the following content:

deb hardy main 
deb-src hardy main

Then, you need to add the key of the repository to your system:

apt-key adv --keyserver --recv-keys ED283389

Finally, run:

apt-get update && apt-get upgrade

You should be prompted about a newer version of nginx, say yes, and that’s it, enjoy ;).