Redirect IP to domain using SSL

I am trying to redirect my IP address to my domain which uses SSL. In my htaccess

I am using following lines:

   RewriteCond %{HTTP_HOST} ^111\.111\.11\.111$
   RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]

Redirect works, but before it is redirected I get SSL certificate error, once I click on proceed (unsafe) it goes to the domain. How do I redirect to domain without going to to the SSL certificate page first?

Answer

For this to be possible, you would need a valid SSL certificate for 111.111.11.111, which is unlikely, see also Is it possible to have SSL certificate for IP address, not domain name?.

What you probably want to do is:

  1. Create a VirtualHost entry matching 111.111.11.111 as ServerName, but not using https, but http instead.
  2. Redirect that to your domain.

You might also consider using mod_alias instead of mod_rewrite, which is considered the cleaner options in this case, see When not to use mod_rewrite.

Attribution
Source : Link , Question Author : DN0300 , Answer Author : Community

Leave a Comment