.htaccess在Apache2中通过SSL/HTTPS访问时不工作


.htaccess not working while accessed via SSL/HTTPS in Apache2

我的.htaccess配置有问题。我的Web服务器是Apache2,我的网站是用PHP编写的。但是,我在.htaccess.上遇到了一些问题

当我通过非ssl访问它时(http://mywebsite.dev),我的.htaccess是工作。我使用.htaccess进行URL重写,并通过自定义模板处理错误。但是,当我通过SSL访问它时(https://mywebsite.dev),对于索引页是有效的。但是,当我访问https://mywebsite.dev/page/about,显示404未找到(显示默认的404未找到页面,而不是我的自定义页面。这意味着,我的.htaccess代码未加载)。

对于我的URL结构http://mywebsite.dev/?load=page&page=关于。如果我访问http://mywebsite.dev/page/about,它有效。但是,不是通过SSL。什么是问题?顺便说一句,我的/etc/apache2/站点可用/website.conf代码是:

<VirtualHost *:80>                                                                          
        ServerName mydomain.com                                                              
        ServerAdmin webmaster@localhost                                                     
        DocumentRoot /var/www/html/website/                                                 
        <Directory /var/www/html/website>                                                   
          Options Indexes FollowSymLinks                                                    
          AllowOverride All                                                                 
          Require all granted                                                               
        </Directory>                                                                        
        # LogLevel info ssl:warn                                                             
        ErrorLog ${APACHE_LOG_DIR}/error.log                                                
        CustomLog ${APACHE_LOG_DIR}/access.log combined                                     
        ErrorLog ${APACHE_LOG_DIR}/error.log                                                
        CustomLog ${APACHE_LOG_DIR}/access.log combined  
        # enabled or disabled at a global level, it is possible to                          
        # For most configuration files from conf-available/, which are                      
        # enabled or disabled at a global level, it is possible to                          
        # include a line for only one particular virtual host. For example the              
        # following line enables the CGI configuration for this host only                   
        # after it has been globally disabled with "a2disconf".                             
        #Include conf-available/serve-cgi-bin.conf 
</VirtualHost>                                                                              

我的.htaccess代码是:

RewriteEngine On                                                                      
RewriteRule ^page/([A-Za-z0-9-]+)/?$ index.php?load=page&page=$1 [NC]                 
ErrorDocument 404 /public/404.html                                                   

我正在使用Laragon在Windows中开发它。生产环境是:Ubuntu 16、PHP 7和Apache2。谢谢

抱歉语法错误,或者你不明白我的意思。非常感谢您阅读我的问题:)

<VirtualHost *:80>行告诉apache,此配置仅适用于来自所有接口(*)的流量,但仅适用于端口80(:80)的流量。AllowOverride All未应用于https(端口443),因为它不匹配。

要解决此问题,您需要另一个虚拟主机<VirtualHost *:443>。您可以在两个虚拟主机中复制内容,也可以使用include,请参阅此服务器故障答案。