0

I'm trying to redirect all http traffic for www.example.com to https://www.example.com, here's my apache2 config:

<VirtualHost *:80>
ServerAlias example.com *.example.com
ServerName www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>

which should redirect everything to:

<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/example/www.example.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/example/www.example.com.key
SSLCertificateChainFile /etc/apache2/ssl/example/gd_bundle.crt
ServerAlias example.com *.example.com
ServerName www.example.com
DirectoryIndex index.php
DocumentRoot /var/www/html/example/www/
...

The SSL site is working fine, but the redirect is not. I've also tried .htaccess, but apache says the rewrite is not allowed in .htaccess. I've tried numerous variations from other posts, but they don't seem to be working.

batflaps
  • 179
  • 1
  • 3
  • 10
  • 1
    Please note that a permanent redirect is supposed to get cached , often almost indefinitely, by browsers. If you made a mistake earlier and keep testing from the same browser tab/window any server side changes won’t be picked up (immediately) Test from a command line with for instance `curl -v example.com` or a new incognito window - your current Config seems ok by the way – HBruijn Jul 10 '19 at 22:01
  • "but the redirect is not" - What happens exactly? Nothing? Incorrect redirect? An error? "apache says the rewrite is not allowed in .htaccess" - How exactly is this reported? With the directives you've shown, `.htaccess` is not _enabled_ - so you wouldn't necessarily expect `.htaccess` to do anything, including report any errors? – MrWhite Jul 15 '19 at 16:14
  • If I allow override to .htaccess, then create an .htaccess with `RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]` apache complains saying redirect not allowed here. – batflaps Jul 15 '19 at 18:54

0 Answers0