0

I know this question has been posted ad-nauseam; however, I still cannot manage to get a working solution.

OS being used is Debian 7 Wheezy.

vHosts file (/etc/apache2/sites-available/default):

<VirtualHost *:80>
  ServerName www.example.com
  ServerAlias *.example.com
  RedirectPermanent / https://www.example.com/
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin domains@example.com
        SSLEngine on
        ServerName www.example.com
        SSLCertificateFile /etc/apache2/ssl/ev-cert.crt
        SSLCertificateKeyFile /etc/apache2/ssl/private.key
        SSLCertificateChainFile /etc/apache2/ssl/intermediate.crt
        SSLProtocol all
        SSLCipherSuite HIGH:MEDIUM
        DocumentRoot /var/www

    <Directory /var/www/>
            Options -Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

        ErrorLog /var/log/apache2/error.log
        LogLevel info
        CustomLog /var/log/apache2/access.log combined
</VirtualHost>

EDIT (Added description of the problem):

Upon restarting apache2, I get no errors; however, when I visit http://www.example.com it goes no where and get a server connection error (cannot connect to server), though when I visit https://www.example.com I get through just fine. There are no logs in apache to indicate a failure.

Jenny D
  • 27,358
  • 21
  • 74
  • 110
Kris
  • 1
  • 2
  • 1
    So you have posted a config, but why not also spend a few minutes and actually describe your problem. What exactly happens when you try to visit the http site? Do you get an error, do you get incorrectly redirected or what? Please don't expect us to reason your mind. – Zoredache Nov 03 '14 at 20:35
  • I apologize for the oversight, I must not have been thinking clearly. I have updated the initial post. – Kris Nov 03 '14 at 20:40
  • Check the firewalls. – Jenny D Mar 19 '19 at 09:14

1 Answers1

-1

You do it wrong. All you need mod_rewrite. So Basicly first check that this module is on in httpd.conf

# vi /usr/local/etc/apache24/httpd.conf
LoadModule rewrite_module libexec/apache24/mod_rewrite.so

create .htaccess in folder you want redirect to https

# touche /usr/local/www/site1/.htaccess

then add rule for redirection

# echo 'RewriteEngine On' >> /usr/local/www/site1/.htaccess
# echo 'RewriteCond %{HTTPS} off' >> /usr/local/www/site1/.htaccess
# echo 'RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}' >> /usr/local/www/site1/.htaccess

Or you can add this line to youre vhost.conf file for http delete RedirectPermanent line and add

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

save and restart apache # apachectl restart P.S. All path for freebsd don't know what os you use.

Kzerza
  • 124
  • 3
  • Thank you very much for your time, however I am either not doing something correctly or it's simply not working: In the .htaccess file I have added what you suggested wrapped by ` and ` In the vhost file I have removed the following line as per your comment it is seemingly erroneous: RedirectPermanent / https://www.domain.com/ – Kris Nov 03 '14 at 21:04
  • Try next `ServerName domain.com` in http part of youre conf. – Kzerza Nov 03 '14 at 21:30
  • Hmmm... No dice; I have triple checked that mod_rewrite is enabled, a2enmod rewrite brings back "Module rewrite already enabled". At the risk of sounding like an idiot, is there anything else I can try? I'm at a loss. This has never not worked for me in the past. – Kris Nov 03 '14 at 21:36