[英]htaccess redirect for subdomains
目前,我有一個網站(example.com)。 http到https重定向的http正在通過我的.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 。
是否可以使用htaccess文件實現此目的,而不會影響我為example.com工作的http到https重定向?
謝謝!
是的,您可以添加多個條件。
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:如果主機是www.subdomain.example.com
,請重定向到https://subdomain.example.com/
2:如果不是https
,則重定向到https
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.