We have a WordPress blog, google is indexing http as well as https urls. Now we are considering to either redirect https to http, or to use https and redirect all http traffic there. And how can we make all necessary changes to our WordPress installation?

  • why do you need to redirect https to http? – Vishwa Apr 30 '19 at 7:04
  • @Vishwa because google is indexing both https and http – meysam Apr 30 '19 at 7:06
  • 1
    you dont need to add both to search console. google always prefer https over http. you dont need to add redirect to make google crawl your http version anyways – Vishwa Apr 30 '19 at 7:08
  • 1
    A verry good answer can be found here: webmasters.stackexchange.com/questions/68435/… – Roy van Wensen Apr 30 '19 at 11:58
  • 3
    I'm curious... if your site is accessible by both HTTP and HTTPS why were you choosing to favor HTTP over HTTPS? Does your site not work properly over HTTPS? I didn't downvote either, but I imagine this is because... .htaccess specific questions are generally off-topic on WordPress SE (these are better suited to the Webmasters Stack). You don't give any specifics as to what "doesn't work"? Errors? Incorrect redirect? Nothing? And... in 2019 there should be no need to redirect HTTPS to HTTP - so what you are suggesting is against all recommendations. – MrWhite Apr 30 '19 at 17:50

If available always use https, it is securer for obvious reasons, it is better received by search engines and browsers nowadays, it is just overall preferable.

1 Backup

Should go without saying, but backup your database. There is always a possibility that something goes wrong. Additionally, make sure you have access – ssh, ftp, etc – to your files, and you have a possibility to access – ssh (mysql, wp-cli), phpmyadmin, etc – the database.

2 Set URL

Either under Dashboard > Settings > General:

enter image description here

Or use constants in wp-config.php:

define( 'WP_HOME','https://example.com' ); 
define( 'WP_SITEURL','https://example.com' ); 

3 Update database

Either use the Search Replace DB tool:

Or make use the WP-CLI command search-replace:

Example: wp search-replace 'http://example.test' 'http://example.com'

Both above options have an option to dry run, test, before making changes.

Bonus, this plugin gets recommended a lot by people I generally trust:

Note: I personally have no experience with the plugin; I'm adding it for completeness’ sake.

4 Enforce redirecting to https

Either via adding the following lines to the .htaccess:

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

Or you can generally set this via your server administration gui, so plesk, cpanel, webmin or whatever your hosting provider is offering.

| improve this answer | |

You can paste this code in the wp-config.php file to define your new URL.

define('WP_HOME','http://yoursite.com'); //Enter your new URL
define('WP_SITEURL','http://yoursite.com'); //Enter your new URL
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.