How to build a WordPress plugin out of this?

Solution: 1

Edit the wp_options table in MySQL and change the values for

  1. siteurl
  2. home

Solution: 2

Try changing your .htaccess file to this (slightly edited):

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]