Steve
Steve

Reputation: 1765

redirect all subdomains from http to https using .htaccess

How do I redirect all subdomains of example.com from http to https using .htaccess?

I've searched Google and can't find a solution.

Upvotes: 0

Views: 4091

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

To redirect all subdomains of example.com to https , you can use :

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.example\.com$
RewriteRule ^ https://%1.example.com%{REQUEST_URI} [NE,L,R]

Upvotes: 5

Related Questions