2013-06-28 39 views
1

我萃取下面的代码从这里在计算器(Enforce www and trailing slash with mod_rewrite htaccess on a multi-domain site)问题,并直接从apache.orgMOD-重写/重写规则:强制的https:// WWW作为协议和域

的情况下由三个要求:

  1. 保证,是生产域以www总是启动。
  2. 不追加WWW。到beta.domain.tld,dev.domain.tld,mobile.domain.tld
  3. 终于保证,每一个URL获取改写为https。

我想出了以下条件:

# Enforce www, if no subdomain is given 
RewriteCond %{HTTP_HOST} !^(beta|dev|mobile|www)\. 
RewriteCond %{HTTPS}s ^on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI}/ [R] 

# Enfore SSL for all Domains 
RewriteCond %{HTTPS} !=on 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 

所提到的规则按预期工作,虽然一个单一的情况下不能正常工作

https://domain.tld/没有正确重定向到https://www.domain.tld/

有人能帮助我吗?

回答

2

试着用这个替换您的2代码:

RewriteCond %{HTTP_HOST} !^(?:beta|dev|mobile|www)\. [NC] 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L] 

RewriteCond %{HTTPS} =off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L] 
+0

THX对于这一点,就像一个风情万种! –

+0

不客气,很高兴它的工作。 – anubhava