繁体   English   中英

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

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

我对.htaccess配置有问题。 我的网络服务器是Apache2,我的网站是用PHP编码的。 但是,.htaccess有一些麻烦。

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

对于我的URL结构,它是http://mywebsite.dev/?load=page&page=about 如果我访问http://mywebsite.dev/page/about ,它将起作用。 但是,不是通过SSL。 怎么了 顺便说一句,我的/etc/apache2/sites-available/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> 您可以在两个虚拟主机中复制内容,也可以使用包含,请参阅此服务器故障解答

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM