简体   繁体   English

Apache2使用ssl重定向到另一个域

[英]Apache2 redirect to another domain with ssl

I have a no clue why this fails. 我不知道为什么会失败。 I just want to redirect all domain to www.maindomain.com and also http to https , what am i missing? 我只是想将所有域名重定向到www.maindomain.com并将http重定向到https ,我缺少什么?

# redirect http to https    
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# redirect without www to www
RewriteCond %{http_host} ^maindomain.com [nc]
RewriteRule ^(.*)$ https://www.maindomain.com  [r=301,nc]

# redirect another domain to www.maindomain.com    
RewriteCond %{HTTPS} off # this i was missing 
RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain.com [NC]
RewriteRule ^(.*)$ https://www.maindomain.com [R=301,L]
  1. http://maindomain.com to https:/www.maindomain.com/ works http://maindomain.comhttps:/www.maindomain.com/工作
  2. http://anotherdomain.com to https:/www.maindomain.com/ works http://anotherdomain.comhttps:/www.maindomain.com/工作
  3. https://anotherdomain.com to https:/www.maindomain.com/ fails https://anotherdomain.comhttps:/www.maindomain.com/失败

The Http to Https redirection for Another domain failed because Your Rule is missing the following line : 另一个域的Http到Https重定向失败,因为您的规则缺少以下行:

RewriteCond %{HTTPS} off

Try : 试试:

# redirect another domain to www.maindomain.com    

RewriteCond %{HTTPS} off

RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain.com [NC]
RewriteRule ^(.*)$ https://www.maindomain.com [R=301,L]

You can try this: 你可以试试这个:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Just copy and paste the above code in .htaccess file then the whole website will be redirected to “https” when the browser is opened in “http” mode. 只需将上述代码复制并粘贴到.htaccess文件中,然后当浏览器以“http”模式打开时,整个网站将被重定向到“https”。 The browser just get redirected using url rewriting in .htaccess. 浏览器只是在.htaccess中使用url重写进行重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM