The following lines are in the .htaccess I wrote.

<IfModule mod_rewrite.c>  
RewriteEngine On
RewriteCond %{HTTP_HOST} ^40.230.60.270
RewriteRule (.*) https://www.mywebsite.com/$1 [R=301,L]
</IfModule>

It redirects when I type this in the browser. http://40.230.60.270

But when I write like this, it doesn’t redirect. https://40.230.60.270

I bought SSL certificate for two years and there was no problem with the certificate.

Can anyone tell me what its rewrite condition is ?

edited by MattIPv4
1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
3 answers

Hello,

Do you have a VirtualHost entry matching the IP address 40.230.60.270 with https and not http? If there is an entry for the IP address with https this will be the reason.

Create a VirtualHost entry matching 40.230.60.270 as ServerName, but not using https, but http instead. Then redirect this to your domain name.

Let me know how it goes.

Alex

  • HTTP Virtual Host with ServerName: mywebsite.com

    HTTPS Virtual Host on ServerName: mywebsite.com

    Are you asking for an IP address on HTTPS Virtual Host ?

    There is no IP address given to my virtual hosts.

    HTTPS will not access any HTTP virtual hosts.

    Do you mean that the problem is in the ServerName ?

    Full HTTPS Virtual Host Write it down pls, so what would that be like.

    • Thanks for confirming this.

      I just wanted to ask if everything is fine with the virtual host configuration.

      Also I have a question, when you access https:/40.230.60.270 you should see a certificate warning page and then you should be redirected to the site itself. You might have already acknowledged the certificate warning, but this is something that will happen for sure.

      Alex

      edited by MattIPv4
      • Yes you are right.

        There it says “Your connection is not private - NET::ERRCERTCOMMONNAMEINVALID”

        Do you think that HTTPS is never redirected ?

        Or it would have redirected but it is not being redirected because of the certificate ?

        Is it stuck on the certificate ?

        Or the virtual host is fine, Rather, it should be redirected from .htaccess

        • This is the normal behavior of a web server, because there is no SSL Certificate installed for the IP address itself and the browser will always give you this warning message regarding the certificate. It’s just how the web server works.

          Let me know if you have any questions.

          Alex

          edited by MattIPv4

Hello.

I am having this same issue. I have tried to create a new VirtualHost entry as my ServerName but the https://ip is not redirecting to https://domain.

Currently the http://ip is redirecting to the https://domain.

When I tried to create a redirect on the VirtualHost on port 443 all my entry points ( https://ip and https://domain ) stop working, giving a ‘not allowed to acess this resource error’.

ServerAdmin webmaster@localhost
DocumentRoot /dev/null
ServerName http://ip
ServerAlias domain.com www.domain.com

I have the same problem, any solution ?

Submit an Answer