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?

New contributor
Swagatam Majumdar is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

marked as duplicate by dan Feb 12 at 7:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.