Ssl – Forwarding 80 to 443 on Nagios woes

.htaccesscentos6mod-rewritenagiosssl

I perhaps just need some extra insight because I don't see where I'm going wrong.
I used an SSL Cert to secure our nagios server. We want to specifically require all traffic over nagios (like 2 users, lol) to use SSL.

So I thought, oh, mod_rewrite + Rewrite Rule in .htaccess, right?

So I went into the DocumentRoot and did a vi .htaccess (one didn't already exist) and then I put in the following rule;

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://our.server.org/$1 [R,L]

This does absolutely nothing. Does nada.

Whhhyy..

Note: AllowOverride all in httpd.conf is on. Also, I verified that the module is not uncommented out … but note, I couldn't find the mod_rewrite module installed so I copied it over from another server and placed it in modules/mod_rewrite.so . It was weird because it was enabled in the httpd.conf file, but then didn't exist in modules …

I'm a baddie 🙁

Best Answer

Here's my redirecting non-ssl VirtualHost in its entirety:

<VirtualHost *:80>
  ServerAdmin root@example.com
  ServerName www.example.com
  ServerAlias example.com

  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

  LogLevel warn    
  CustomLog /var/log/apache2/access.log vhost_combined
  ErrorLog /var/log/apache2/error.log
</VirtualHost>

This belongs in the Apache config rather than in .htaccess.

The main difference is in our RewriteCond lines, where yours is %{SERVER_PORT} 80 and mine is %{HTTPS} !=on.