{"id":3511,"date":"2020-08-18T12:02:29","date_gmt":"2020-08-18T06:32:29","guid":{"rendered":"https:\/\/www.suramya.com\/blog\/?p=3511"},"modified":"2022-06-16T15:21:33","modified_gmt":"2022-06-16T09:51:33","slug":"finally-moved-the-website-blog-to-https","status":"publish","type":"post","link":"https:\/\/www.suramya.com\/blog\/2020\/08\/finally-moved-the-website-blog-to-https\/","title":{"rendered":"Finally moved the Website &#038; Blog to https"},"content":{"rendered":"<p>After spending way too much time avoiding the work due I finally configured both suramya.com &#038; the Blog to be https by default. The setup was fairly simple, I added the certificate on the 1and1.com portal, then after a few mins I was able to access the site over https. In order to redirect http to https automatically I followed the following steps:<\/p>\n<p><b>Auto Redirect to https in Apache<\/b><\/p>\n<p>Configure <i>.htaccess<\/i> to force a redirect, you can also configure it in the Apache main configuration (under the virtualhosts directive) but since I don&#8217;t have root access and can&#8217;t modify it I updated the .htaccess config to do the same thing. Basically you need to add the following lines to <i>.htaccess<\/i> :<\/p>\n<pre class='code'>\r\nRewriteEngine On\r\nRewriteCond %{SERVER_PORT} 80\r\nRewriteRule ^(.*)$ https:\/\/www.suramya.com\/$1 [R,L]\r\n<\/pre>\n<p>Change www.suramya.com to your domain, else every visitor to your site will be sent to my site. Not that I will mind that, but you might. \ud83d\ude42<\/p>\n<p>Then I did the same thing for the blog with a small change, The .htaccess for the blog reads as the following:<\/p>\n<pre class='code'>\r\n<ifmodule mod_rewrite.c>\r\nRewriteEngine On\r\nRewriteCond %{SERVER_PORT} 80\r\nRewriteRule ^(.*)$ https:\/\/www.suramya.com\/blog\/$1 [R,L]\r\n<\/ifmodule>\r\n<\/pre>\n<p>When updating the file, you need to ensure you put the changes outside the <i># BEGIN WordPress<\/i> &#038; <i># END WordPress<\/i> as the content is dynamically generated and would be overwritten. <\/p>\n<p><b>Updating all the urls in WordPress<\/b><\/p>\n<p>After I made the changes above, I found that the site was being redirected to https but I was getting errors about mixed content on the page because all the URL&#8217;s\/Images that I had uploaded to WP till now were saved as http and not https. So I had to change every URL in the blog from http to https and to be honest I wasn&#8217;t looking forward to doing this manually. I searched the web and found <a href=\"https:\/\/help.dreamhost.com\/hc\/en-us\/articles\/360003304711-Changing-all-URLs-in-your-WordPress-database\">this site<\/a> that had instructions on how to update the url&#8217;s using the WordPress commandline interface. From the blog directory you need to issue the following command:<\/p>\n<pre class='code'>wp search-replace http:\/\/www.suramya.com\/blog\/ https:\/\/www.suramya.com\/blog\/ --dry-run<\/pre>\n<p>This command does a dry run and tells you what all changes will be made and if everything looks ok, then you can run the above command again without the &#8216;dry-run&#8217; call.<\/p>\n<pre class='code'>wp search-replace http:\/\/www.suramya.com\/blog\/ https:\/\/www.suramya.com\/blog\/<\/pre>\n<p>If all goes well you will get an output similar to the following:<\/p>\n<pre class='code'>(uiserver):~\/public_html\/suramya.com\/blog$ wp search-replace http:\/\/www.suramya.com\/blog\/ https:\/\/www.suramya.com\/blog\/ \r\n+------------------+-----------------------+--------------+------+\r\n| Table            | Column                | Replacements | Type |\r\n+------------------+-----------------------+--------------+------+\r\n| wp_commentmeta   | meta_key              | 0            | SQL  |\r\n| wp_commentmeta   | meta_value            | 572          | PHP  |\r\n| wp_comments      | comment_author        | 0            | SQL  |\r\n| wp_comments      | comment_author_email  | 0            | SQL  |\r\n| wp_comments      | comment_author_url    | 29           | SQL  |\r\n| wp_comments      | comment_author_IP     | 0            | SQL  |\r\n| wp_comments      | comment_content       | 2            | SQL  |\r\n| wp_comments      | comment_approved      | 0            | SQL  |\r\n| wp_comments      | comment_agent         | 0            | SQL  |\r\n| wp_comments      | comment_type          | 0            | SQL  |\r\n| wp_links         | link_url              | 0            | SQL  |\r\n| wp_links         | link_name             | 0            | SQL  |\r\n| wp_links         | link_image            | 0            | SQL  |\r\n| wp_links         | link_target           | 0            | SQL  |\r\n| wp_links         | link_description      | 0            | SQL  |\r\n| wp_links         | link_visible          | 0            | SQL  |\r\n| wp_links         | link_rel              | 0            | SQL  |\r\n| wp_links         | link_notes            | 0            | SQL  |\r\n| wp_links         | link_rss              | 0            | SQL  |\r\n| wp_options       | option_name           | 0            | SQL  |\r\n| wp_options       | option_value          | 3            | PHP  |\r\n| wp_options       | autoload              | 0            | SQL  |\r\n| wp_postmeta      | meta_key              | 0            | SQL  |\r\n| wp_postmeta      | meta_value            | 0            | PHP  |\r\n| wp_posts         | post_content          | 591          | SQL  |\r\n| wp_posts         | post_title            | 0            | SQL  |\r\n| wp_posts         | post_excerpt          | 0            | SQL  |\r\n| wp_posts         | post_status           | 0            | SQL  |\r\n| wp_posts         | comment_status        | 0            | SQL  |\r\n| wp_posts         | ping_status           | 0            | SQL  |\r\n| wp_posts         | post_password         | 0            | SQL  |\r\n| wp_posts         | post_name             | 0            | SQL  |\r\n| wp_posts         | to_ping               | 0            | SQL  |\r\n| wp_posts         | pinged                | 20           | SQL  |\r\n| wp_posts         | post_content_filtered | 0            | SQL  |\r\n| wp_posts         | guid                  | 2775         | SQL  |\r\n| wp_posts         | post_type             | 0            | SQL  |\r\n| wp_posts         | post_mime_type        | 0            | SQL  |\r\n| wp_term_taxonomy | taxonomy              | 0            | SQL  |\r\n| wp_term_taxonomy | description           | 0            | SQL  |\r\n| wp_termmeta      | meta_key              | 0            | SQL  |\r\n| wp_termmeta      | meta_value            | 0            | SQL  |\r\n| wp_terms         | name                  | 0            | SQL  |\r\n| wp_terms         | slug                  | 0            | SQL  |\r\n| wp_usermeta      | meta_key              | 0            | SQL  |\r\n| wp_usermeta      | meta_value            | 0            | PHP  |\r\n| wp_users         | user_login            | 0            | SQL  |\r\n| wp_users         | user_nicename         | 0            | SQL  |\r\n| wp_users         | user_email            | 0            | SQL  |\r\n| wp_users         | user_url              | 0            | SQL  |\r\n| wp_users         | user_activation_key   | 0            | SQL  |\r\n| wp_users         | display_name          | 0            | SQL  |\r\n+------------------+-----------------------+--------------+------+\r\nSuccess: Made 3992 replacements.\r\n<\/pre>\n<p>That&#8217;s it. After running the command, the blog is completely on https and the security gods are happy :). Now I need to update all the URL&#8217;s on the main site to reference https instead of http and that is going to be painful. It will require a whole lot of script-fu to do it automatically as it will have to be a regex\/awk or something similar. Maybe someone already did the work and posted the solution online. Alas that was not the case. I ended up manually updating the files since there were only about 20-25 of them. Opened all of them in the editor one-shot and then did a search &#038; replace. Now both sites are coming up properly in https. <\/p>\n<p>&#8211; Suramya<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After spending way too much time avoiding the work due I finally configured both suramya.com &#038; the Blog to be https by default. The setup was fairly simple, I added the certificate on the 1and1.com portal, then after a few mins I was able to access the site over https. In order to redirect http [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[9,2,10],"tags":[],"class_list":["post-3511","post","type-post","status-publish","format-standard","hentry","category-computer-hintstips","category-techie-stuff","category-website-updates"],"_links":{"self":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/3511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/comments?post=3511"}],"version-history":[{"count":7,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/3511\/revisions"}],"predecessor-version":[{"id":3525,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/3511\/revisions\/3525"}],"wp:attachment":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/media?parent=3511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/categories?post=3511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/tags?post=3511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}