If you are looking to change the preview link of the WordPress post without actually changing the configuration file, then you are right place.

One of the simplest ways to change the preview link of posts is to simply go to General > Site Address and update the value.

However, this would affect the entire links in the posts and pages. I wanted to change the preview link only. To do that, open functions.php by going to Appearance > Theme editor.

Add the following code at the end of the file.

add_filter( 'preview_post_link', 'the_preview_fix' );

function the_preview_fix() {
    $slug = basename(get_permalink());
    return "https://yourdomain.com/$slug";
}

Change the domain and path of the article according to your domain name and permalink.

Save the file and you can now preview your posts and pages on a custom preview link.