通过 htaccess 使用子域和 www 转换进行 http 到 https 重定向

克鲁姆

我需要每次调用特定的子域。example.com.xx 在开头添加 www,然后将其重定向到 https。

htaccess 重定向到 https://www有一个解决方案,但不适用于 sub.example.com.xx 重定向到https://www.sub.example.com.xx

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

如果我输入http://sub.example.com ..,我会得到https://sub.example.com.xx而不是https://www.sub.domain.com.xx

即使使用http://yyy.sub.example.com.xx 也必须给我https://www.yyy.sub.example.com.xx

例子:

example.com.xx ---> https://www.example.com.xx
http://example.com.xx ---> https://www.example.com.xx
https://example.com.xx ---> https://www.example.com.xx

sub.example.com.xx ---> https://www.sub.example.com.xx
http://sub.example.com.xx ---> https://www.sub.example.com.xx
https://sub.example.com.xx ---> https://www.sub.example.com.xx

other.sub.example.com.xx ---> https://www.other.sub.example.com.xx
http://other.sub.example.com.xx ---> https://www.other.sub.example.com.xx
https://other.sub.example.com.xx ---> https://www.other.sub.example.com.xx
十字架

您可以使用:

# redirect to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

# Redirect http to https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

首先是 www,以避免双重重定向。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

htaccess重定向到https:// www

HTACCESS通过HTTPS重定向添加WWW

htaccess中的http到https以及www重定向到非www

.htaccess文件未重定向http:// www。到https:// www

htaccess将多个域(https和http,www和非www)重定向到一个https域

如何通过web.config将http重定向到https和www重定向到非www?

.htaccess将http / https www重定向到https non-www

Nginx 301将http(裸和www)重定向到https www,并将通配符子域重定向到https

尝试将非www和http重定向到htaccess中的www和https太麻烦了

如何使用htaccess文件将http重定向到https://www.example.com?

301重定向(.htaccess)-http到https + www到非www +'index.php'到'/'

在.htaccess中将http重定向到https并将www重定向到非www

301通过htaccess将index.html以及所有http,https,www和非www版本的首页URL重定向到https:// www根URL

使用htaccess将多个域(http https www和non-www)重定向到新域

如何将http重定向到https和将https:// www重定向到https://

重定向http:// www。以及将根域和子域的http://转换为https

.htaccess将所有内容重定向到https非www和404进行索引

通过一次重定向将http://域转换为https:// www

使用mod_rewrite和htaccess将主域重定向到https,但将所有子域重定向到http

是否从htaccess中的裸http和https域重定向到https:// www域?

通过.htaccess将非www重定向到www(子域除外)

通过htaccess将http://重定向到https://www.www

htaccess重定向到“ https:// www”。

如何使用htaccess将www和非www重定向到特定域的https

重定向www。到非www并使用.htaccess将所有http重定向到https

htaccess:将所有子域重定向到主要的https www域

.htaccess http www 或非 www 重定向到 https

使 .htaccess 从一个域重定向到另一个域以用于 WWW(http://www. 和 https://www.)、HTTP 和 HTTPS

使用 htaccess 将 http:// 和 http://www 重写/重定向到 https://