.htaccess 为子域强制 http
.htaccess force http for sub domain
我已经将我的主站点设置为使用 https。我强制用户使用 .htaccess 访问 https。我用这个代码
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
但是我有一个子域。这就是所谓的 xxx
。它的内容位于 ./xxx
。如何强制 xxx.domain.com
只使用 http?
你可以使用这个
RewriteEngine on
#redirect www urls to non-www.
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/ [R=301,L]
# do nothing if sub.domain.com is requested
RewriteCond %{HTTP_HOST} ^sub.domain.com$
RewriteRule ^ - [L]
#redirect the main domain to https
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
在测试之前清除浏览器缓存。
我已经将我的主站点设置为使用 https。我强制用户使用 .htaccess 访问 https。我用这个代码
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
但是我有一个子域。这就是所谓的 xxx
。它的内容位于 ./xxx
。如何强制 xxx.domain.com
只使用 http?
你可以使用这个
RewriteEngine on
#redirect www urls to non-www.
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/ [R=301,L]
# do nothing if sub.domain.com is requested
RewriteCond %{HTTP_HOST} ^sub.domain.com$
RewriteRule ^ - [L]
#redirect the main domain to https
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
在测试之前清除浏览器缓存。