【发布时间】:2018-05-15 23:12:13
【问题描述】:
我需要对特定子域的每次调用。example.com.xx 在开头添加 www,然后将其重定向到 https。
htaccess redirect to 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
【问题讨论】:
标签: .htaccess redirect https subdomain