【问题标题】:.htaccess http to https redirect [closed].htaccess http 到 https 重定向 [关闭]
【发布时间】:2012-11-19 22:49:03
【问题描述】:

我目前正在使用以下 htaccess 将我的网站重定向到 https 和 www(如果尚未使用)。

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

但是,我有一个无法重定向到 https 的子域 forum.example.com,因为它是一个论坛并且包含不安全的内容。

当我在我的 htaccess 中使用上述代码时,它会将论坛重定向到 https://www.example.com/forum 而不仅仅是 forum.example.com。

(基本上我需要一份来自 melt-wow.com 的 htaccess 的精确副本)

注意他们有 https,但论坛没有重定向。

有什么建议吗?如果我不清楚或者您需要澄清任何事情,请告诉我,我会澄清。

提前致谢

【问题讨论】:

    标签: .htaccess http redirect https web


    【解决方案1】:

    这是一个想法:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/forum/
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
    

    【讨论】:

    • 不幸的是,这不起作用,仍然将论坛重定向到 https
    【解决方案2】:

    试试

    #if not forum.example.com, not www.example.com and not ssl then redirect
    RewriteCond %{HTTP_HOST} !^forum\. 
    RewriteCond %{HTTP_HOST} !^www\. 
    RewriteCond %{SERVER_PORT} !443
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R,L]
    
    #if not forum.example.com, www.example.com, and not ssl then redirect
    RewriteCond %{HTTP_HOST} !^forum\. 
    RewriteCond %{HTTP_HOST} ^www\. 
    RewriteCond %{SERVER_PORT} !443
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
    
    #redirect if https://forum.example.com
    RewriteCond %{HTTP_HOST} ^forum\.
    RewriteCond %{SERVER_PORT} 443
    RewriteRule ^(.*)$ http://forum.%{HTTP_HOST}/$1 [R,L]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2012-11-02
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    相关资源
    最近更新 更多