Question

I have an apache2 server running on Ubuntu that I am toying with to step my sys admin skills up. I've been trying to set up a webserver with HTTPS throughout the entire site. Currently, If I go to https://mysite.com it works just fine. I've tried a few different redirect rules to make all connections to the site be forced to HTTPS, but I'm having no luck. Can anyone point out my mistake here?

httpd.conf:

NameVirtualHost *:443

<VirtualHost *:443>
        ServerName mysite.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
        SSLEngine on
        SSLOptions +FakeBasicAuth -StrictRequire +ExportCertData
        SSLCertificateKeyFile /etc/ssl/crt/myserver.key
        SSLCertificateFile /etc/ssl/crt/mysite_com.crt
        SSLCertificateChainFile /etc/ssl/crt/mysite.ca-bundle
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride AuthConfig Options FileInfo Limit
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

<IfModule !mod_rewrite.c>
    LoadModule rewrite_module modules/mod_rewrite.so
</IfModule>


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

ports.conf:

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

Any help is greatly appreciated!

Was it helpful?

Solution

Finally figured it out... It wasn't my rewrite rule that wasn't working, but rather a conflict with the proxy I was using (cloudflare). For those in a similar situation, you have to create a "Page Rule" within the cloudflare dashboard, otherwise it will ignore you Apache rules.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top