Redirecting to https

On Centos 7 I placed this in httpd.conf:

<Files /var/www/html/>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}:443%{REQUEST_URI}

I only have one domain on this server. The one issue I have is if the IP address is typed in directly it does not redirect too https://the_ip. Anyway to make that work?

Where in httpd.conf did you place it? Inside a section? Or just “bare” without any <foo bar> and </foo> around it?

Anyway, do note that redirecting to an IP address with HTTPS will not work in case of a Let’s Encrypt certificate, as Let’s Encrypt doesn’t issue certificates with an IP address as a SAN (or CN for that matter). Therefore, redirecting to an IP address with HTTPS with a LE cert will give the client an error (CN mismatch).

I just put it towards top. The forum removed part in previous post.

<Files /var/www/html/>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}:443%{REQUEST_URI}
</Files>

I know it will give an error but it will still be encrypted.

Dealing with this in your virtual host Apache config may be easier. No debugging mod_redirect syntax.

Something like this…

<VirtualHost *:443>

  ServerName  www.yourdomainhere.com

  Redirect 301 / https://yourdomainhere.com/

  ... ... ...

</VirtualHost>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.