MR.Internet
MR.Internet

Reputation: 645

url redirect from http to https - Domain and sub Domain unlike

I have the following code, which suppose to work both for domain-name and sub-domain-name redirection to https.

But, in fact it redirects all to main domain name.

Example.

Main domain - example.com and www.example.com
Sub Domain - aa.example.com and www.aa.example.com

Here is the code I have...

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(aa|bb)\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

What the above code works is that, the example.com and www.example.com works fine. But when i come to aa.example.com or www.aa.example.com it redirects to example.com

What did I do wrong?

Upvotes: 0

Views: 49

Answers (1)

Panama Jack
Panama Jack

Reputation: 24478

You should be able to try something like this and it will get main and sub domain.

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

Upvotes: 1

Related Questions