I tried the following .htaccess code to redirect the IP address of my VPS server to my domain, but despite of all efforts it keeps resulting in a 404 error:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxx.xxx.xxx.xxx
RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]

I have other redirects in my .htaccess which are working normally.

Can someone help me to solve this problem?


It seems it's solved now, but it is working only when I put HTTPS before the IP. It does not work with the default HTTP.

Any clues?