1

When I enter my website's non-SSL URL "cms00.example.com" into my browser, it won't redirect to https://cms00.example.com. If I enter the HTTP address, I can see the site and if I enter the HTTPS address, I can see the site. I just can't get the redirect from http to https to work. I've read numerous articles on how to do this and tried all the suggestions but my configuration still isn't working. I'm running Apache 2.4.10 on Debian 8, and this is my first time working with Apache.

I've run these two commands and verifed that the rewrite and ssl modules have been loaded:

sudo a2emod rewrite   # <- already enabled
sudo a2emod ssl       # <- already enabled

I haven't made any modifications to /etc/apache2/apache2.conf and I haven't created any additional .htaccess files.

Here is my configuration file:

# /etc/apache2/sites-available/vhosts.conf
DirectoryIndex index.php index.html

<VirtualHost *:80>
  ServerName cms00.example.com
  DocumentRoot "/var/www/html"
  Redirect permanent / https://cms00.example.com
</VirtualHost>

<VirtualHost *:443>
  ServerName cms00.example.com
  DocumentRoot "/var/www/html"

  SSLEngine on
  SSLCipherSuite AES256+EECDH:AES256+EDH
  SSLProtocol All -SSLv2 -SSLv3
  SSLHonorCipherOrder On
  SSLCompression off
  SSLCertificateFile /etc/apache2/ssl/example.com.crt
  SSLCertificateKeyFile /etc/apache2/ssl/private/example.com.key

  <Directory "/var/www/html">
    AllowOverride All
    Options -Indexes +FollowSymLinks
    Require all granted
  </Directory>
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
  • Your rewrite for http to https is inside your https virtual host. That's not what you want. The http virtualhost never sees it. – yoonix Dec 11 '17 at 23:38
  • So are you saying the RewriteCond and RewriteRule directives should go in the VirtualHost *:80 block? Thanks. – Jim Dec 11 '17 at 23:48
1

I've solved the problem. Here's what's going on. /etc/apache2/apache2.conf includes a call to any config files that have symlinks in /etc/apache2/sites-enabled. Since there was a symlink in that directory pointing to /etc/apache2/sites-available/000-default.conf, that latter config file was being loaded and it was over-riding the blocks and directives in my vhosts.conf file. Once I deleted that symlink, my vhosts.conf settings were able to take effect. The lesson for me was that any file that has a symlink in sites-enabled will be enabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.