开发者

htaccess redirect all subdomains to https except www

开发者 https://www.devze.com 2023-03-12 14:20 出处:网络
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

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

Any ideas greatfully appreciated.

开发者_开发问答

Here's what I have so far:

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

Thanks!


Try this code in your .htaccess file:

Options +FollowSymlinks -MultiViews
RewriteEngine On

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


This should help you:

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

First RewriteCond: If the website doesn't start with www

Second RewriteCond: Get any subdomain

Third RewriteCond: Check that https isn't already within the requested url

RewriteRule: Redirect to https version of site

0

精彩评论

暂无评论...
验证码 换一张
取 消