HTTPS custom endpoint for Wordpress

I have been able to create a custom endpoint following the code below for wordpress

function handle_woocommerce_keys($request){
    $user_id = $request[user_id];

/* search user_id in db and store the keys as meta_data */

    $response = new WP_REST_Response();

    return $response;

add_action('rest_api_init', function () {
    register_rest_route( 'village/v1', 'authkeys',array(
        'methods'  => 'POST',
        'callback' => 'handle_woocommerce_keys'

Unfortunatly it's only working using HTTP. I use Postman and it behave has expected. However, I need HTTPS to be supported. The reason is that the endpoint URL is provide as param to a server and used by this server to send a POST to this https URL.

Any idea how to make HTTPS endpoint supported on Wordpress ? Thanks

1 answer

  • answered 2020-10-01 07:26 Diego

    There are a few things to do to convert your WP from http to https. The suggestion is:

    1.List item ( with the replace command ( to change all your DB occurrences from to The full command should be something like:

    wp search-replace --precise --all-tables-with-prefix

    2.Edit your .htaccess inside your root dir and add this at the top:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    3.Edit your wp-config.php and add this (OPTIONAL):

    define('FORCE_SSL_ADMIN', true);

    After you did all of this you should be ready to use HTTPS, as long as you have a valid certificate :)