• 0

[htaccess] Redirect primary domain from http to https but exclude all subdomains


Question

Hi

I want to redirect my primary domain to https (http://www.website.com to https://www.website.com) and exclude all sub domains. (http://xyz.website.com to remain as http://xyz.website.com)

I have been on google for too long and couldnt find the right solution, please help

My .htaccess file

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

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

thanks for the reply

we have multiple sub domains around 30+, which are not supposed to be https ... they should be only http

by enforcing these commands in .htaccess these subdomains are not working

Link to comment
Share on other sites

  • 0
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]

Let's give this a shot. This will redirect domain.com to www.domain.com and then to https://www.domain.com.

if www.domain.com is already found, it will redirect that to HTTPS. My URL rewrites are a little rusty since I use Laravel a lot these days and all of my subdomains are SSL so I don't have to do much with htaccess lately :/

Link to comment
Share on other sites

This topic is now closed to further replies.