2016-08-03 77 views
2

我遇到了.htaccess配置问题。我的网络服务器是Apache2,我的网站由PHP编码。但是,我在.htaccess中遇到了一些麻烦。.htaccess在通过Apache2中的SSL/HTTPS访问时无法正常工作

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

对于我的网址结构,它是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 [email protected]              
     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             

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

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

回答

3

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

要解决此问题,您需要其他虚拟主机<VirtualHost *:443>。您可以复制两个虚拟主机中的内容或使用包含,请参阅此server fault answer

+0

你的意思是,我需要用不同的端口创建新的虚拟主机,通过https处理请求,我错了吗? CMIIW。感谢您的回应。 – filosofikode

+0

对,你需要两个虚拟主机来处理http和https(服务器故障问题就是这样)。如果你可以通过https访问你的服务器,你已经有一个'SSLEngine on'(和其他'SSLCertificateFile'),你可能需要修改/重用它。 –