skip to Main Content

I want to redirect my website to https://subdomain.domain.com in my .htaccess file.

Redirects:

http://subdomain.domain.com => https://subdomain.domain.com

http://www.subdomain.domain.com => https://subdomain.domain.com

https://www.subdomain.domain.com => https://subdomain.domain.com

https://subdomain.domain.com => no redirects

2

Answers


  1. This should do it…

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    Login or Signup to reply.
  2. First rule redirect all www to https://subdomain.domain.com, second all http to https://subdomain.domain.com

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^www. [NC]
    RewriteRule (.*) https://subdomain.domain.com/$1 [R=301,L]
    
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://subdomain.domain.com/$1 [R=301,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search