0

few days ago I have asked my host to install an SSL certificate, to be able to load my website through https protocol. The website is now running via https properly, but I noticed that Google started indexing my website by using the IP Address instead of the domain name and this is caused some pages not being indexed properly.

After the certificate was installed, I created an .htaccess with the following code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^11\.11\.11\.111$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
</IfModule>

(IP and DOMAIN are masked, if you need actual IP and domain, I can provide them)

I was expecting all requests via IP address and via "www.example.com" to be redirected properly to "https://example.com" with https protocol and without www.

Unfortunately, if I try to type "http://11.11.11.111/" I'm being redirected properly to "https://example.com/" but if I try "https://11.11.11.111/" I am not and I get a warning (of course the certificate is not for IP address, but for domain name).

How can I force redirecting also for https + IP Address by using an htaccess declaration?

Can you please tell me what I'm doing wrong?

Thank you very much in advance for any help.

Mighty Gorgon
  • 33
  • 1
  • 5
  • if you want to redirect all request to https, you should redirect using Redirect permanent / https://mysite.example.com/ this link could help https://stackoverflow.com/questions/16200501/http-to-https-apache-redirection – Lety Aug 20 '19 at 21:00
  • _“How can I force redirecting also for https + IP Address by using an htaccess declaration?”_ - you simply can’t, as long as you don’t get a certificate that works for the IP address as well. Without a valid certificate for that situation, it doesn’t ever get so far that your .htaccess could have any effect – the requesting client will cancel the process before that point, because there is no valid certificate for the IP. – misorude Aug 21 '19 at 08:36

0 Answers0