Reject if request on ip address

How do I return 403 if request is for the IP address and not for a domain name?

i.e. reject if 1.2.3.4 and accept if domain.com