在Apache(ubuntu)上将非www https重定向到www https

Ash*_*rke 7 apache ssl redirect

我知道类似的问题一再被问到,但是看了之后我仍然无法使我的服务器正常工作.

我的服务器上安装了SSL证书.

当我点击https://www.ashleyclarke.me - >一切都很好

当我点击http://www.ashleyclarke.me - >重定向到https://www.ashleyclarke.me

当我点击http://ashleyclarke.me - >重定向到https://www.ashleyclarke.me

我的问题是当我点击https://ashleyclarke.me时,我试图设置重定向但没有运气.

<VirtualHost *:443>
    ServerAdmin me@ashleyclarke.me
    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 me@ashleyclarke.me
    ServerName www.ashleyclarke.me
    ServerAlias ashleyclarke.me
    Redirect permanent / https://www.ashleyclarke.me
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

您的建议表示赞赏.

Pet*_*oop 5

我自己也遇到了类似的问题,并在这里找到了答案:https : //stackoverflow.com/a/9945842/883960

SSL协商发生在服务器响应之前-因此,要真正做到这一点,您需要ashleyclarke.me(不带www。)的SSL证书,并设置第二个:443 VirtualHost进行重定向。