Redirect access by IP address to domain name

I’d like to redirect (block?) all access to my NC via IP address and redirect them to domain name - so I DO NOT want to block certain IP addresses from accessing my NC I just want a redirect them and prevent usage of server’s IP address i.e. if my NC server has an IP address of and my domain name is I want to redirect to

I’ve tried adding
RewriteEngine On
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$$1 [L,R=301]
to /var/www/.htaccess as well as /var/www/nextcloud.htaccess
but with no effect.

Is this even impossible?


There are several ways, but first: do you have a reverse proxy in front?

Hi jtr,

as far as I’m aware I’m not using reverse proxy.