【问题标题】:htaccess force https & www to non-www, but subdomain only httpshtaccess 强制 https 和 www 到非 www,但子域仅 https
【发布时间】:2016-11-28 12:02:30
【问题描述】:

我有两个网站

  1. yourdomain.com
  2. reseller.yourdomain.com

现在我想通过 apache htaccess 重定向强制两个域使用 https。除此之外,主域应始终使用 www 而不是非 www。但是子域 reseller.yourdomain.com 当然不应该使用 www。

重定向应该是什么样子?我已经尝试了很多类似的东西

RewriteEngine on
RewriteCond %{HTTPS} !^on

RewriteCond %{HTTP_HOST} !^reseller\.yourdomain\.com [NC]

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

这不是 100% 有效,主域正确重定向到 www 和 ssl,subomdain 的 ssl 重定向仅适用于 reseller.yourdomain.com,不适用于 reseller.yourdomain.com/single-page 等子站点.

谢谢!

【问题讨论】:

标签: apache .htaccess redirect ssl


【解决方案1】:

这样试试吧,

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.+)\.yourdomain.com$
RewriteRule ^ https://%1.yourdomain.com [R=301,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-16
    • 2011-06-17
    • 2015-07-18
    • 1970-01-01
    • 2014-02-23
    • 2016-04-05
    • 2011-09-14
    • 2015-05-10
    相关资源
    最近更新 更多