【问题标题】:htaccess main domain to https, subdomain to httphtaccess 主域到 https,子域到 http
【发布时间】:2017-09-19 19:18:09
【问题描述】:

我已经尝试在我的 .htaccess 文件中添加 2 天了,但我无法让它正常工作。

我在一家公司工作,他们需要这种特定的重定向到他们的网站和子域,因为他们的 joomla 设置需要它。

所有场景:

主域

http://www.my-main.be -> https://www.my-main.be

http://my-main.be -> https://www.my-main.be

https://www.my-main.be -> https://www.my-main.be

https://my-main.be -> https://www.my-main.be

子域

http://www.mysub.my-main.be -> http://mysub.my-main.be

http://mysub.my-main.be -> http://mysub.my-main.be

https://www.mysub.my-main.be -> http://mysub.my-main.be

https://mysub.my-main.be -> http://mysub.my-main.be

注意:

  • mysub 可能是固定的,但首选动态的,因此所有子域都转到 http://。
  • 在主域中有 www 很重要
  • 将 www 排除在子域之外很重要

这可能吗?

如果我解释得不够清楚,请发表评论,我会进一步澄清。

提前致谢

【问题讨论】:

  • 主域和子域的 DocumentRoot 是否指向同一位置?
  • 是的,只安装了一个 joomla 实例
  • 您能否展示您现有的 .htaccess 问题
  • 这两天我改了很多。我现在拥有的最新版本甚至还没有接近工作。但我也可能会在 Fiverr 上发布它,因为它必须尽快准备好
  • 没有稳定版本了。目前所有链接都被重定向到 https//www,因为这是主网站现在工作的唯一方式。我们网站上每天有 100 多个订单,所以我不能乱搞它。你可以看到上面的所有场景,如果你真的需要代码示例,你可以在stackoverflow.com/questions/29088257/…或stackoverflow.com/questions/27882723/…看到

标签: .htaccess redirect mod-rewrite


【解决方案1】:

您可以在RewriteEngine 行下方设置这些规则:

RewriteEngine On

# for main domain
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(my-main\.be)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

# for sub domain
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(mysub\.my-main\.be)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]

# rest of rules go here

清除浏览器缓存后进行测试。

【讨论】:

    【解决方案2】:

    请检查以下两个规则也适用于动态子域

    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
    
    RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^(?:www\.)?((.*))$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-22
      相关资源
      最近更新 更多