Skip to content

Instantly share code, notes, and snippets.

@CTimmerman
Last active August 29, 2015 14:24
Show Gist options
  • Save CTimmerman/f1e35e3666569a389ed6 to your computer and use it in GitHub Desktop.
Save CTimmerman/f1e35e3666569a389ed6 to your computer and use it in GitHub Desktop.
Redirect permanently all domains to one (HTTPS) - Apache config
RewriteCond %{HTTP_HOST} !^www\.company\.com$ [NC] # nocase
RewriteRule (.*) https://www.company.com/$1 [NE,R=301,L] # noescape, redirect, last
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/wildcard-company-com.cer
SSLCertificateKeyFile /etc/apache2/ssl/myserver.key
SSLCACertificateFile /etc/apache2/ssl/CA.cer
RewriteEngine On
RewriteCond %{HTTP_HOST} !^company\.com [NC] # nocase
RewriteRule ^/(.*)$ https://company.com/$1 [NE,R=301,L] # noescape, redirect, last: http://httpd.apache.org/docs/2.4/rewrite/flags.html
</VirtualHost>
@CTimmerman
Copy link
Author

.htaccess worked better for non subdomains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment