kikerrobles
kikerrobles

Reputation: 2269

htaccess quite domains not www to https://www but not subdomains to www

I've found quite examples but all of them for an especific domain, and my server has many main domains and subdomains.

I want all main domains to be rewrite to https://www but the subdomains to https:// only:

main-domain.xxx       -> https://www.main-domain.xxx
sub.main-domain.xxx   -> https://sub.main-domain.xxx

I'm using now this rules to get https://

RewriteCond %{REQUEST_SCHEME} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Upvotes: 0

Views: 26

Answers (1)

kikerrobles
kikerrobles

Reputation: 2269

I've found this as a question not as an answer but works fine for me:

RewriteCond %{REQUEST_SCHEME} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Upvotes: 1

Related Questions