Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect non-www https to www https on apache not working as expected

I know that similar questions have been asked over and over, however after looking at them I have still not been able to get my server working properly.

I have an SSL certificate installed on my server.

When i hit https://www.ashleyclarke.me -> all is good

when i hit http://www.ashleyclarke.me -> redirects to https://www.ashleyclarke.me

when i hit http://ashleyclarke.me -> redirects to https://www.ashleyclarke.me

My problem is when I hit https://ashleyclarke.me, I have tried to set a redirect but with no luck.

<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName www.ashleyclarke.me
    ServerAlias ashleyclarke.me

    DocumentRoot /var/www/ashleyclarke.me/public

    <Directory /var/www/ashleyclarke.me/public>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/ashleyclarke.me-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/ashleyclarke.me-access.log combined

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/ashleyclarke.me.crt
    SSLCertificateKeyFile /etc/apache2/ssl/ashleyclarke.me.key
    SSLCACertificateFile /etc/apache2/ssl/PositiveSSLCA2.crt

</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.ashleyclarke.me
    ServerAlias ashleyclarke.me
    Redirect permanent / https://www.ashleyclarke.me
</VirtualHost>

Your advice is appreciated.

like image 877
Ashley Clarke Avatar asked Mar 31 '14 02:03

Ashley Clarke


People also ask

Why is HTTPS redirect not working?

Issues from redirecting HTTP to HTTP can be due to the following reasons: Incomplete transfer or change of domain website to HTTPS. Not updating the URLs. Using expired SSL certificates.


1 Answers

Just ran into a similar problem myself and found the answer here: https://stackoverflow.com/a/9945842/883960

SSL negotiation happens before the response from the server - so to actually do this you'll need an SSL certificate for ashleyclarke.me (without the www.) and setup a second :443 VirtualHost to just redirect.

like image 168
Petecoop Avatar answered Oct 12 '22 17:10

Petecoop