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> 
2
  • Your rewrite for http to https is inside your https virtual host. That's not what you want. The http virtualhost never sees it. Commented Dec 11, 2017 at 23:38
  • So are you saying the RewriteCond and RewriteRule directives should go in the VirtualHost *:80 block? Thanks. Commented Dec 11, 2017 at 23:48

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.