0 votes
329 views
by (270 points)
retagged by

I bought a wild certificate for main domain & my sub domains problem is somebody visit its go directly https site but some reason sub-domain redirect is not happening my .htaccess is given below for reference

# for main domain

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]

# for sub domain Indian customer 

RewriteCond %{HTTP_HOST} ^(www\.)?in\.domain\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://in.domain.com%{REQUEST_URI} [R=301,L,NE]

# for sub domain for US customer 

RewriteCond %{HTTP_HOST} ^(www\.)?us\.domain\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://us.domain.com%{REQUEST_URI} [R=301,L,NE]
by (10.3k points)
Assuming you have created subdomains with their own directories. You should place their .htaccess in respective directory. Not in public_html or top folder.
by (270 points)
thanks for your prompt reply.  yes, subdomain is created like this for indian customer (IN directory) international customer (US directory) for subdomain can i do any change http to https because certificate is applicable for all sub-domain also

1 Answer

0 votes
by (10.3k points)

Just put following code snippet into the .htaccess file in the root folder of the website. Mostly public_html. Remember to remove the same/alike code from .htaccess if any.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

It will redirect all to https:// from http://. It will work as wildcard redirect engine.

...