2016-04-21 31 views
1

我有一个名为域:example.com和一个叫子域名:sub.example.comHTTPS子域不正确htaccess的重定向

我要强制为example.com中的所有主域请求到https: //除了1个文件夹。例如:

http://www.example.com/ <-- Redirect all requests to https:// 
http://www.example.com/folder/ <-- Force to http:// not https:// 

我也想强制sub.example.com的所有子域请求到https://除了1个文件夹。例如:

http://sub.example.com <-- Redirect all requests to https:// 
http://www.example.com/folder/ <-- Force to http:// not https:// 

目前example.com是工作的罚款,并强制将https://开头的主域和文件夹重定向没有到https://但是文件夹没有强制执行的http://如果有人选择https://

如果我访问http://sub.example.com它不强制执行https://,如果我手动访问https://sub.example.com,它会在url中显示。但是它显示的网站实际上是从https://www.example.com

htaccess的文件我有example.com是:

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]   
    RewriteCond %{HTTP_HOST} !^sub.example.com$ [NC] 
    RewriteCond %{REQUEST_URI} !^/folder/ 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,QSA,L] 

</IfModule> 

htaccess的文件我有sub.example.com是:

RewriteEngine on 
RewriteBase/
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/folder/ 
RewriteCond %{HTTP_HOST} ^example\.com\.au$ [NC] 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

回答

0

我发现了这个问题。它与htaccess文件无关。我发现我已经安装到主域上​​的证书并且子域没有匹配的证书。

Apache被重定向到ssl证书域而不是子域。我通过购买通配符ssl解决了这个问题,将其安装到主域上​​,然后将其分别安装到子域。

这解决了这个问题。