0

As suggested here, I am using the following code in the Apache configuration file (default-ssl.conf in this case)

<VirtualHost *:80>
    ServerName name.domain.com
    Redirect / https://name.domain.com/
</VirtualHost>

I've restarted Apache and... nothing. No error, no redirect. Http is served as http, https is served as https. What did I do wrong? My domain name doesn't start with "www" but I can't imagine that making a difference.

Stumbler
  • 2,056
  • 7
  • 35
  • 61

1 Answers1

0

Not sure if this helps, Also some time the browsers dose DNS cache try clearing it, in chrome you can goto chrome://net-internals/#dns and clear it, or use another browser to test.

<VirtualHost *:80>
  DocumentRoot /home/webroot/example.com/htdocs

  ServerName example.com
  ServerAlias www.example.com

  <Directory /home/webroot/example.com/htdocs>
    FileETag MTime Size
    DirectoryIndex index.php index.html index.htm
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  RewriteEngine on
  Redirect permanent / http://www.example.com/
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

  ErrorLog /home/webroot/example.com/logs/error_log
  CustomLog /home/webroot/example.com/logs/access_log combined
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /home/webroot/example.com/htdocs

  ServerName www.example.com

  RewriteEngine on
  Redirect permanent / http://www.example.com/
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

  ErrorLog /home/webroot/example.com/logs/error_log
  CustomLog /home/webroot/example.com/logs/access_log combined
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Keyur Padalia
  • 2,077
  • 3
  • 28
  • 55
  • That's having no effect either (either positive or negative). Definitely not a DNS cache problem. It seems that everything between and is being ignored... – Stumbler Aug 16 '17 at 09:43
  • I have edited my answer have a look if that helps, also don't forget to restart httpd – Keyur Padalia Aug 16 '17 at 09:53
  • Thanks for the help. I realised what the problem was. default-ssl.conf is only used for configuration with ssl, and is too late to tell it anything about http at that stage. The code you describe, if placed in 000-default.conf (ubuntu server 14.4) works however. – Stumbler Aug 16 '17 at 10:07
  • Ooh that's a shame, I am not much familiar to Ubuntu – Keyur Padalia Aug 16 '17 at 10:09