如何使用php或.htaccess设置所有链接到https?

How to set all link to https using php or .htaccess ?

with this code

<?PHP
$path_image = "404.png";
?>
<img src="<?PHP echo $path_image; ?>">

when inspect elements it's show

<img src="404.png">

i want to change inspect view to

<img src="https://www.example.com/404.png">

How can i do that with php or .htaccess ?

I suggest you use .htaccess for force redirect with SSL

Note: htaccess can not change your HTML but it can redirect to https

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

and if want to do with php than you have need to HTTP_HOST and after that manuly redirect to https://hostname/$your_url