簡體   English   中英

如何使用SSL將非www重定向到www的特定域,而不是所有駐留域

[英]How to redirect non-www to www with SSL for a specific domain not all parked domains

我將test.yoursite.com停在example.com並且具有SSL多域證書。

我要問的是:

  • http://example.com請求時,.htaccess應將其重定向到https://www.example.com
  • http://test.yoursite.com請求htaccess時,應將其重定向到https://test.yoursite.com

方向之一應與www重定向和SSL重定向一起使用,另一方向僅適用於SSL重定向。

順便說一句,我也有example.net停在同一主機上。 我已經嘗試了幾種無效的方法。 等待您的幫助。

嘗試

# Dealing with a domain with/without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ https://www.%2.%3/$1 [L,R]

# Dealing with a domain that doesn't care about www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ https://%1.%2.%3/$1 [L,R]

第一條規則會將http://www.example.com/something重定向到https://www.example.com/something以及http://example.net/foo重定向到https://www.example.net / foo

第二條規則會將不關心“ www”的主機(例如http://subdomain.domain.com/bar)重定向到https://subdomain.domain.com/bar

但是,它不會重定向http://sub-sub.subdomain.domain.com/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM