-1

For redirecting my sub domain http: to https:

I used below code in .htaccess file but it didn't work.

RewriteEngine on

RewriteCond %{HTTP_HOST}  ^subdomain\.example\.com$ [NC]
RewriteRule ^$ https://subdomain.example.com/ [R=301,NE,NC,L]

Also, I have already changed from http to https in WordPress site URL, but still it is not working.

Please guide me how to fix it.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • Possible duplicate of [Best Practice: 301 Redirect HTTP to HTTPS (Standard Domain)](https://stackoverflow.com/questions/29029049/best-practice-301-redirect-http-to-https-standard-domain) – Walf Jul 24 '17 at 14:08
  • Don't create duplicate questions. This has been asked a great many times already on this site. – Walf Jul 24 '17 at 14:11

1 Answers1

0
RewriteCond %{HTTP_HOST}  ^subdomain\.example\.com$ [NC]
RewriteRule ^$ https://subdomain.example.com/ [R=301,NE,NC,L]

This simply checks the host, not the SSL state (ie. HTTP or HTTPS). This also only redirects the site root and would result in a redirect loop.

Try the following instead. This will need to go before the existing (WordPress) directives in .htaccess:

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,NE,L]

You will need to clear your browser cache before testing.

MrWhite
  • 43,179
  • 8
  • 60
  • 84