【问题标题】:Apache configuration for slim3 with ssl带有 ssl 的 slim3 的 Apache 配置
【发布时间】:2025-12-24 07:00:15
【问题描述】:

我正在尝试使用我的超薄框架应用程序设置我的 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 没有问题。

【问题讨论】:

    标签: apache ssl slim-3


    【解决方案1】:

    尝试将RewriteBase 设置为/

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

    【讨论】: