{"id":262,"date":"2019-11-01T20:33:56","date_gmt":"2019-11-01T20:33:56","guid":{"rendered":"http:\/\/blog.davcloud.top\/?p=262"},"modified":"2020-01-28T19:53:58","modified_gmt":"2020-01-28T19:53:58","slug":"262","status":"publish","type":"post","link":"https:\/\/blog.davcloud.top\/?p=262","title":{"rendered":"Switch http to https for WordPress"},"content":{"rendered":"\n<h2>Abstract<\/h2>\n\n\n\n<p>This article aims to record how to switch http to https on WordPress.<\/p>\n\n\n\n<p class=\"has-text-color has-vivid-red-color\">Attention: Please make sure the WordPress service can be accessed by http protocol, or you may not access to the service after you switch to https with following steps.<\/p>\n\n\n\n<h2>Step 1. Open the wp-config.php file<\/h2>\n\n\n\n<p>Open the wp-config.php file. Assume the root dir of the wordpress is \u201cwordpress\u201d. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># If the dir required root permission, add sudo at the beginning.\nvim \/wordpress\/wp-config.php<\/code><\/pre>\n\n\n\n<h2>Step 2. Edit the file<\/h2>\n\n\n\n<p>Add the code below the first <em><code>&lt;?php<\/code><\/em> in the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$_SERVER['HTTPS'] = 'on';\ndefine('FORCE_SSL_LOGIN', true);\ndefine('FORCE_SSL_ADMIN', true);<\/code><\/pre>\n\n\n\n<h2>Step 3. Change the website address<\/h2>\n\n\n\n<p>Change the website to the correct https address in the admin page, which is in the Settings\/General page. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"725\" height=\"121\" src=\"https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/11\/image-2.png\" alt=\"\" class=\"wp-image-271\" srcset=\"https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/11\/image-2.png 725w, https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/11\/image-2-300x50.png 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/figure><\/div>\n\n\n\n<h2>Step 4. Config Apache Virtualhost file<\/h2>\n\n\n\n<p>Create a apache config file for the wordpress service, assume the apache installed in <em><code>\/etc\/httpd<\/code><\/em>, and the file named <code><em>blog.conf<\/em><\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/httpd\/conf.d\/blog.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>SSLPassPhraseDialog  builtin\nSSLSessionCache         shmcb:\/var\/cache\/mod_ssl\/scache(512000)\nSSLSessionCacheTimeout  300\nSSLRandomSeed startup file:\/dev\/urandom  256\nSSLRandomSeed connect builtin\nSSLCryptoDevice builtin\nSSLProtocol all -SSLv2 -SSLv3\nSSLHonorCipherOrder on\nSSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4:\n\n&lt;VirtualHost _default_:80>\n    # Use the correct website instead\n    Servername www.example.com\n    ErrorLog logs\/error_log\n    TransferLog logs\/access_log\n    LogLevel warn\n\n    # 301 jump\n    RewriteEngine on\n    RewriteCond   %{HTTPS} !=on\n    RewriteRule   ^(.*)  https:\/\/%{SERVER_NAME}$1 &#91;L,R] \n&lt;\/VirtualHost>\n\n&lt;VirtualHost _default_:443>\n    # Use the correct website instead\n    Servername www.example.com\n    ErrorLog logs\/ssl_error_log\n    TransferLog logs\/ssl_access_log\n    LogLevel warn\n    SSLEngine on\n    # Use the real path of certificate file instead\n    SSLCertificateFile path_of_cert_file\n    SSLCertificateKeyFile path_of_cert_key_file\n    RewriteEngine On\n\n    SetEnvIf Authorization \"(.*)\" HTTP_AUTHORIZATION=$1\n    ProxyPass \/ http:\/\/www.example.com\/\n    ProxyPassReverse \/ http:\/\/www.example.com\/\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>In the listen of port 80, we use 301 jump to force use https instead of http.<\/p>\n\n\n\n<h2>Step 5. Reload Apache service and access the WordPress with https website<\/h2>\n\n\n\n<p>Reload the apache service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl reload httpd<\/code><\/pre>\n\n\n\n<p>Access the service with https address, it is ok now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Abstract This article aims to record how to switch http to https on WordPress. Attention: Please make sure the WordPress service can be accessed by http protocol, or you may not access to the service after you switch to https with following steps. Step 1. Open the wp-config.php file Open the wp-config.php file. Assume the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[109,108,107,31],"_links":{"self":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/262"}],"collection":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=262"}],"version-history":[{"count":15,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":823,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/262\/revisions\/823"}],"wp:attachment":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}