Correctly force SSL on wordpress via wp-config.php

PHP code doesn't have to deal with SSL at all in such case. Here applies classical SoC principle: if you code doesn't explicitly work with connection (in WP it does not), you should leave protocol checking to web server.

You should also avoid defining port in your rewrite rules. In case you're not using multisite WP setup, you could try:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

i used this one. which is fine to go on.

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
   $_SERVER['HTTPS']='on';

if your server port is differed from 443. you can specify it . Otherwise, no need to use it once again .