繁体   English   中英

htaccess url将http www和非www重写为https www + https非www重写为https www

[英]htaccess url rewrite http www and non-www to https www + https non-www to https www

我正在寻找一组重写规则,该规则将执行以下操作:

  • http www和http non-www到https www
  • https非www到https www

您也可以说我希望所有不等于https://www.somedomain.com的 url都重写为https://www.somedomain.com

我已经看到了很多答案,但是我找不到与上述内容匹配的一组重写规则,并且很难将其中的一些规则组合成可以完成上述任务的一组可靠规则。

提前致谢!

您可以在DOCUMENT_ROOT/.htaccess文件中使用以下单个规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?somedomain1\.com$
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.somedomain1.com%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTP_HOST} ^(?:www\.)?somedomain2\.com$
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.somedomain2.com%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?somedomain1\.com$
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.somedomain1.com%{REQUEST_URI} [NE,R=301,L]

它对我https://somedomain1.com ,但https://somedomain1.com不会重定向到https://www.somedomain1.com

暂无
暂无

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

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