Andrea
Andrea

Reputation: 273

in htaccess force https just if domain contains "-facebook"

How to force HTTPs just if the domain contains -facebook?

I mean for example force HTTPs if domain is demo-facebook.domainname.com

Rewrite rule is this

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [NC,L,R]

but I have problem with the RewriteCond

All rule conditions that I found are related to words inside the URL not in the domain.

Upvotes: 1

Views: 43

Answers (1)

anubhava
anubhava

Reputation: 785561

You will need a RewriteCond using HTTP_HOST variable to compare a substring in domain name like this:

RewriteEngine On

RewriteCond %{HTTP_HOST} -facebook\.domainname\.com$ [NC]
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

Upvotes: 1

Related Questions