Rewrite https except subdomain?

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 25
Joined: 13 Aug 2014, 07:47

Rewrite https except subdomain?

22 Mar 2015, 18:47

Hi!

I have these rules:
#Redirect non-HTTPS to HTTPS

RewriteCond %{HTTP:Host} (.*)
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (.*)
RewriteRule .? https://%1%2 [R,L]

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

I want these things to work.
http://www.domain.com -> https://www .domain.com
http://domain.com -> https://www.domain.com


But this NOT to redirect to https:
http://test.domain.com

This subdomain I want to remain "as is".
Is there a way to rewrite code for this to work? I tried to modify the code above but never got it to work :/
Now it redirects all the 2 examples correct, but not the fourth.
Is there a way to "exclude" "test.domain.com" from all theses redirects?

Best regards
Fredrik

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite https except subdomain?

23 Mar 2015, 16:31

Hello Fredrik,

Please try using the following code:

#Redirect non-HTTPS to HTTPS

RewriteCond %{HTTP:Host} ^(?!test\.domain\.com)(.*)
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (.*)
RewriteRule .? https://%1%2 [R,L]

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!(?:www\.|test\.domain\.com))(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

User avatar
Posts: 25
Joined: 13 Aug 2014, 07:47

Re: Rewrite https except subdomain?

24 Mar 2015, 16:42

Thanks! :D
It works like a charm!

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 38 guests