简体   繁体   English

htaccess重定向子域名

[英]htaccess redirect for subdomains

Currently, I have a website (example.com). 目前,我有一个网站(example.com)。 http to https redirect is working via my .htaccess file http到https重定向的http正在通过我的.htaccess文件工作

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This website also runs on subdomains. 该网站也在子域上运行。

If someone goes to www.subdomain.example.com of the website, I want them to be redirected to https://subdomain.example.com . 如果有人访问该网站的www.subdomain.example.com,我希望将它们重定向到https://subdomain.example.com

Is it possible to achieve this with the htaccess file without impacting the http to https redirect that I have working for example.com? 是否可以使用htaccess文件实现此目的,而不会影响我为example.com工作的http到https重定向?

Thanks! 谢谢!

Yes, you can add multiple conditions. 是的,您可以添加多个条件。

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.subdomain\.example\.com$ [NC]
RewriteRule ^(.*)$ https://subdomain.example.com/$1 [R=301,L]

RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

1: If the HOST is www.subdomain.example.com , redirect to https://subdomain.example.com/ 1:如果主机是www.subdomain.example.com ,请重定向到https://subdomain.example.com/

2: If its not https , redirect to https . 2:如果不是https ,则重定向到https

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM