HTTPS非WWW到https WWWHTTPS、WWW、https

2023-09-02 11:41:03 作者:任性のㄝ子

我重写所有非www请求到www有:

i rewrite all non-www requests to www with:

RewriteCond %{HTTP_HOST} !^www.mydomain.de$
RewriteRule ^(.*)$ http://www.mydomain.de/$1 [L,R=301]

不过... 以https这种doesn't工作,所以我也希望所有的HTTPS请求加www到https以www。 例如:

But... this doesn´t work with https, so I also want all https requests without www to https with www. Example:

https : // mydomain . de --> https : // www . mydomain . de
https://mydomain.de/example --> https://www.mydomain.de/example

体质有人能帮助我吗? 在此先感谢!

Con someone help me here? Thanks in Advance!

推荐答案

您可以使用此code:

You can use this code:

## add www to a domain name
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

这将执行:

在HTTPS => HTTPS与WWW重写 在HTTP => HTTP与WWW重写