使用SSL的slim3的Apache配置

时间:2018-12-02 00:39:57

标签: apache ssl slim-3

我正在尝试使用我的苗条框架应用程序设置我的apache配置文件以使用ssl。我过去已经这样做过,但是由于任何原因,当我尝试访问除主页以外的任何页面时,都出现404错误。这是我的apache配置文件:

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
    RewriteCond %{SERVER_NAME} =www.my-site.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    ServerAdmin my.email@gmail.com
    ServerName www.my-site.com
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /path/to/cert.pem
    SSLCertificateKeyFile /path/to/privkey.pem

    ServerAdmin my.email@gmail.com
    DocumentRoot /wwwroot/sites/my-site/public
    ServerName www.my-site.com
    ErrorLog logs/www.my-site.com-error_log
    CustomLog logs/www.my-site.com-access_log common

    <Directory "/wwwroot/sites/my-site/public">
        AllowOverride All

        RewriteEngine On
        RewriteBase /wwwroot/sites/my-site/public
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [QSA,L]
    </Directory>
</VirtualHost>

如前所述,我的主页完全按照我期望的那样工作。但是当我尝试转到https://www.my-site.com/another/page时,出现404错误。

我在另一个不使用https的服务器上设置了该项目的开发版本,并且在进入http://dev.my-site.com/another/page时也没有问题。

1 个答案:

答案 0 :(得分:0)

尝试将RewriteBase设置为/

<Directory "/wwwroot/sites/my-site/public">
    AllowOverride All

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</Directory>