0

I have a two websites

  1. yourdomain.com
  2. reseller.yourdomain.com

Now I want to forcing both domains to use https via apache htaccess redirect. In addition to that, the main domain should use always www instead of non-www. But the subdomain reseller.yourdomain.com shouldn't use www of course.

How should the redirect look like? I have tried so many things like

RewriteEngine on
RewriteCond %{HTTPS} !^on

RewriteCond %{HTTP_HOST} !^reseller\.yourdomain\.com [NC]

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This works not 100%, the main domain redirects correctly to www and ssl, the ssl-redirect for the subomdain works only on reseller.yourdomain.com, not on sub-sites like reseller.yourdomain.com/single-page.

thanks!

user6573193
  • 339
  • 9
  • 20
  • read here, i may hold your answer: http://stackoverflow.com/questions/20894947/force-https-and-www-for-domain-and-only-https-for-subdomains-htacess – andrew Nov 28 '16 at 12:20
  • doesnt work :-( the subdomain reseller.yourdomain.de redirects on the maindomain. – user6573193 Nov 28 '16 at 12:53

1 Answers1

0

Try it like this,

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.+)\.yourdomain.com$
RewriteRule ^ https://%1.yourdomain.com [R=301,L]
Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45