Yogeswaran
Yogeswaran

Reputation: 13

Domain redirect only for primary domain not add on domains

I want to redirect all http request to https. The problem I am experiencing is that it redirect all add on domains too. I want to redirect only primary domain. Here is my htaccess code -

This will enable the Rewrite capabilities:

RewriteEngine On

This checks to make sure the connection is not already HTTPS:

RewriteCond %{HTTPS} !=on

This rule will redirect users from their original location, to the same location but using HTTPS. The leading slash is made optional so that this will work either in httpd.conf or .htaccess context:

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

What can I do to make sure it only redirects on the primary domain?

Upvotes: 1

Views: 74

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

If you want to redirect a specific domain from http to https you can use the following :

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://% {SERVER_NAME}/$1 [R,L]

This will redirect http://example.com/ to https://example.com/ .

Upvotes: 1

Related Questions