Redirect IP to domain using SSL

5,196

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.

Share:
5,196

Related videos on Youtube

DN0300
Author by

DN0300

Updated on September 18, 2022

Comments

  • DN0300
    DN0300 over 1 year

    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?

    • DerfK
      DerfK about 8 years
      If someone enters https://111.111.11.111/ there is no way to redirect them until after they have securely connected.
    • DN0300
      DN0300 about 8 years
      Even when I enter 111.111.11.111 it redirects to 111.111.11.111 before it goes to my domain