Regex 重写有www和无www的规则
我搜索了很多,但我找不到我的具体问题的答案 当前所有用户重定向到Regex 重写有www和无www的规则,regex,apache,.htaccess,mod-rewrite,rewrite,Regex,Apache,.htaccess,Mod Rewrite,Rewrite,我搜索了很多,但我找不到我的具体问题的答案 当前所有用户重定向到https://www.mydomain.com如果他们键入以下内容之一 http://mydomain.com(将http替换为https,并在此处添加www) http://www.mydomain.com(此处将http替换为https) https://mydomain.com(在此处附加www) 对于上述情况,我在.htaccess中有此代码 RewriteCond %{HTTPS} !=on RewriteRule
https://www.mydomain.com
如果他们键入以下内容之一
(将http替换为https,并在此处添加www)http://mydomain.com
(此处将http替换为https)http://www.mydomain.com
(在此处附加www)https://mydomain.com
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我不知道如何停止任何子域的重定向。e、 g.如果键入以下内容,则不应将用户重定向到https
:
(子域可以是任何名称)abc.mydomain.com
http://abc.mydomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
尝试:
kj有一些相关问题——不是100%——但很有用——嘿,阿努巴瓦,它不起作用。我得到循环重定向错误。Anubhava,你的代码只对www有效,没有www。但它仍然不会停止子域的重定向。仍在重定向到。我不希望我的子域重定向到SSL。是的,我犯了一个错误,现在修复了它。Try againIt不适用于子域。当我键入abc.mydomain.com时。它将其重定向到
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]