簡體   English   中英

htaccess 將所有子域重定向到 https 除了 www

[英]htaccess redirect all subdomains to https except www

I'd like to redirect all subdomains (i've wildcard subdomains set up in apache virtualhost) to https, if http, for all except www.domain.com

任何想法都非常感謝。

這是我到目前為止所擁有的:

# Redirect subdomains to https
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^(*)\. [NC]
#RewriteCond %{HTTP_HOST} !^(www)\. [NC]
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

謝謝!

在您的 .htaccess 文件中嘗試此代碼:

Options +FollowSymlinks -MultiViews
RewriteEngine On

RewriteCond %{SERVER_PORT} =80
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

這應該可以幫助您:

RewriteCond %{HTTP_HOST} !^(www\.)localhost.com$
RewriteCond %{HTTP_HOST} ^(.*?)\.localhost.com$
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*?)$ https://%{HTTP_HOST} [nc]

First RewriteCond : 如果網站不以 www 開頭

第二次RewriteCond :獲取任何子域

第三次RewriteCond :檢查 https 是否已經在請求的 url 中

RewriteRule : 重定向到 https 版本的站點

暫無
暫無

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

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