[英]htaccess url rewrite http www and non-www to https www + https non-www to https www
I am looking for a set of rewrite rules that will do the following: 我正在寻找一组重写规则,该规则将执行以下操作:
You could also say i want all url's that aren't equal to https://www.somedomain.com , rewritten to https://www.somedomain.com . 您也可以说我希望所有不等于https://www.somedomain.com的 url都重写为https://www.somedomain.com 。
I have seen a lot of answers, but i couldn't find a set of rewrite rules that matches the above and difficulty combining some of them to one solid set of rules that will accomplish the above. 我已经看到了很多答案,但是我找不到与上述内容匹配的一组重写规则,并且很难将其中的一些规则组合成可以完成上述任务的一组可靠规则。
Thanks in advance! 提前致谢!
You can use this single rule for that in your DOCUMENT_ROOT/.htaccess
file: 您可以在
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]
It's working for me except https://somedomain1.com
that isn't redirected to https://www.somedomain1.com
它对我
https://somedomain1.com
,但https://somedomain1.com
不会重定向到https://www.somedomain1.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.