title: apache redrict 301 from https://www.domain.com to https://domain.com
body: <p>im trying for hours to redrict https:// www. domain .com to https:// domain .com with 301.</p>
  
  <p>I have a certificate for domain .com but no wildcard for www. domain .com.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond        %{HTTPS}        =on
  RewriteCond        %{HTTP_HOST}    ^www\.meinedomain\.de$ [NC]
  RewriteRule        ^(.*)            https://meinedomain.de/$1 [L,R=301]
  </code></pre>
  
  <p>and </p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTPS} on
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Redirect 301 / https://mineyourmind.de/
  </code></pre>
  
  <p>None of this works. Any ideas what could be wrong? I have added this directly to the apache settings and it is working great for http:// www. domain .com and http:// domain .com to https:// domain .com but not for https:// www. domain .com.</p>
  
  <hr>
  
  <p>At the moment I use the following config. Every redrict works fine, instead of the <a href="https://www.mineyourmind.de" rel="nofollow">https://www.mineyourmind.de</a> to <a href="https://mineyourmind.de" rel="nofollow">https://mineyourmind.de</a></p>
  
  <p>How should such a file look like ?</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName mineyourmind.de
      ServerAlias www.mineyourmind.de
      Redirect 301 / https://mineyourmind.de/ 
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:443&gt;
      ServerAdmin **
      DocumentRoot /var/www/mineyourmind
      ServerName mineyourmind.de
      ServerAlias www.mineyourmind.de
      SSLEngine on
      SSLCertificateFile    /etc/**
      SSLCertificateKeyFile /etc/**
      SSLCertificateChainFile /etc/**
      SSLCACertificateFile /etc/**
  
      RewriteEngine On
      RewriteCond %{HTTPS} on
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  
      &lt;Directory /&gt;
          Options FollowSymLinks
          AllowOverride None
          Order deny,allow
          deny from all
      &lt;/Directory&gt;
      &lt;Directory /var/www/mineyourmind/&gt;
          Options -Indexes FollowSymLinks MultiViews
          AllowOverride All
          Order allow,deny
          allow from all
      &lt;/Directory&gt;
  
      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
      &lt;Directory "/usr/lib/cgi-bin"&gt;
          AllowOverride None
          Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
          Order allow,deny
          Allow from all
      &lt;/Directory&gt;
  
      ErrorLog ${APACHE_LOG_DIR}/error.log
  
      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel warn
  
      CustomLog ${APACHE_LOG_DIR}/access.log combined
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <hr>
  
  <p>Second Edit:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName mineyourmind.de
      ServerAlias www.mineyourmind.de
      RewriteEngine On
      RewriteCond %{HTTPS} off [OR]
      RewriteCond %{HTTP_HOST} ^www\.mineyourmind\.de$ [NC]
      RewriteRule (.*) https://mineyourmind.de%{REQUEST_URI} [R=301,L]
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:443&gt;
      ServerAdmin **
      DocumentRoot /var/www/mineyourmind
      ServerName mineyourmind.de
      ServerAlias www.mineyourmind.de
      SSLEngine on
      SSLCertificateFile    /etc/apache2/**
      SSLCertificateKeyFile /etc/apache2/ssl/**
      SSLCertificateChainFile /etc/apache2/ssl/**
      SSLCACertificateFile /etc/apache2/ssl/**
      RewriteEngine On
      RewriteCond %{HTTPS} off [OR]
      RewriteCond %{HTTP_HOST} ^www\.mineyourmind\.de$ [NC]
      RewriteRule (.*) https://mineyourmind.de%{REQUEST_URI} [R=301,L]
      &lt;Directory /&gt;
          Options FollowSymLinks
          AllowOverride None
          Order deny,allow
          deny from all
      &lt;/Directory&gt;
      &lt;Directory /var/www/mineyourmind/&gt;
          Options -Indexes FollowSymLinks MultiViews
          AllowOverride All
          Order allow,deny
          allow from all
      &lt;/Directory&gt;
  
      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
      &lt;Directory "/usr/lib/cgi-bin"&gt;
          AllowOverride None
          Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
          Order allow,deny
          Allow from all
      &lt;/Directory&gt;
  
      ErrorLog ${APACHE_LOG_DIR}/error.log
  
      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel warn
  
      CustomLog ${APACHE_LOG_DIR}/access.log combined
  &lt;/VirtualHost&gt;
  </code></pre>