Setting Clean URL with https(SSL) for the backend and http for the front end when Drupal is in a subdirectory/ subdomain

This write up needs (technical) review. Don't just copy and paste this code unless you have at least some understanding of the matter.

In Drupal 7 in order to run https(SSL) for the admin backend and run a normal http on the front I had to do the following. This code is intented for if the backend is running on a subdomain/ subdirectory on SSL with a different URL address then the http address of the front end, and with clean URLs enabled.

The first $base_url is the one where you have your admin backend. The second is for your website front end. What this does is when you type the address check whether we are on a https or a http connection. Then the if the address match the $base_url either become a https or a http connection and go to the $base_url that is set.

Now this will work fine as is without the Clean URL enabled. However when you enable Clean URL it stops working. The reason is that we have to set the rewritebase, but where do we set the rewritebase to? If we set it to the subdirectory for the back end then the front end URLs error out. If we set it to the front end then the back end URLs error out. If we leave it as is the front end will work, but the backend won't work. According to the Drupal Docs this can be solved as follows:

In the Drupal .htaccess in your subdirectory where you have Drupal installed replace: