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

查看:167
本文介绍了htaccess的URL重写HTTP www和非www到https的www + HTTPS非www到https WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一套重写规则,这将做到以下几点:

I am looking for a set of rewrite rules that will do the following:

  • 在HTTP www和HTTP非www到https WWW
  • HTTPS非www到https WWW

您也可以说,我希望所有的URL是不等于 https://www.somedomain.com ,改写为 https://www.somedomain.com

You could also say i want all url's that aren't equal to https://www.somedomain.com, rewritten to 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.

在此先感谢!

推荐答案

您可以使用,在你的 DOCUMENT_ROOT /的.htaccess 文件这一单一的规则:

You can use this single rule for that in your DOCUMENT_ROOT/.htaccess file:

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]

这篇关于htaccess的URL重写HTTP www和非www到https的www + HTTPS非www到https WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆