【问题标题】:htaccess redirect for subdomainshtaccess 重定向子域
【发布时间】:2019-10-13 14:21:23
【问题描述】:

目前,我有一个网站 (example.com)。 http 到 https 重定向正在通过我的 .htaccess 文件工作

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

这个网站也在子域上运行。

如果有人访问网站的 www.subdomain.example.com,我希望他们被重定向到 https://subdomain.example.com。

是否可以在不影响我为 example.com 工作的 http 到 https 重定向的情况下使用 htaccess 文件实现这一点?

谢谢!

【问题讨论】:

标签: apache .htaccess


【解决方案1】:

是的,您可以添加多个条件。

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:如果HOST是www.subdomain.example.com,重定向到https://subdomain.example.com/

2:如果不是https,则重定向到https。

【讨论】:

  • 如何防止子域和域被硬编码?我的站点将为每个站点运行多个域和多个子域。
猜你喜欢
  • 2012-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多