title: Redirect domain https://domain.com to https://www.domain.com without rewrite rules just redirect in apache
body: <p>I'm trying to redirect from <a href="https://domain.com" rel="nofollow">https://domain.com</a> to <a href="https://www.domain.com" rel="nofollow">https://www.domain.com</a>,</p>
  
  <p>I can achieve the following task with rewrite, but only want it via redirect 301.</p>
  
  <pre><code>VirtualHost domain.com:80 
  RewriteEngine on 
  ReWriteCond %{SERVER_PORT} !^443$ 
  RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [NC,R,L] 
  VirtualHost _default_:443 
  ServerAdmin webmaster@localhost 
  ServerName domain.com:443 
  ServerAlias www.domain.com 
  DocumentRoot /var/www/html 
  RewriteEngine on 
  RewriteCond %{HTTP_HOST} !^(www\.)?(.+) 
  RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
  </code></pre>
  
  <p>Redirect is not working for me as I tried to redirect <code>/</code> to <code>https://</code> but its redirecting to <code>https://domain.com</code> not <code>https://www.domain.com</code>   </p>