0

When I navigate to http://example.com it correctly redirects to https://example.com.

The problem I'm having is that when I navigate to http://example.com/sub/directory/page.htm it redirects to https://example.comsub/directory/page.htm.

Why is it not redirecting to https://example.com/sub/directory/page.htm?

Here is the apache config:

<VirtualHost *:80>
        ServerName example.com

        Redirect permanent / https://example.com/

</VirtualHost>

<IfModule mod_ssl.c>

#NameVirtualHost *:443

<VirtualHost *:443>

        ServerName example.com

        [...]

        ProxyRequests Off
        ProxyPass               /          http://localhost:8444/
        ProxyPassReverse        /          http://localhost:8444/

</VirtualHost>

The Apache version I am using:

Server version: Apache/2.4.18 (Ubuntu)
Server built:   2017-09-18T15:09:02
crmepham
  • 115
  • 4

1 Answers1

2

Your configuration seems correct:

Redirect permanent / https://example.com/

The Redirect directive should append everything from after the URL-path verbatim to the target. A request for http://example.com/sub/directory/page.htm should indeed append sub/directory/page.htm to https://example.com/ and redirect to https://example.com/sub/directory/page.htm

Your remark "when I navigate to" seems to indicate that you are testing from a webbrowser.

That has a number of potential issues specific to using modern browsers:

  • Browsers cache permanent redirects so any changes you make in Apache configuration won't be picked up, your webbrowser will go directly to the cached target URL, without first connecting to your webserver.
  • Most sites which support TLS and redirect from http to https also set HTTP Strict Transport Security headers. That should also have the effect that your browser won't connect to your plain http site and will actively rewrite the plain http URL's you enter to https.
  • There may also be multiple (cached) redirects and/or rewrite rules active on not only your HTTP site but also on the HTTPS site

Sometimes testing from a new incognito/anonymous browser window prevents such issues, but mostly I simply test from a command line e.g. curl -v http://example.com/sub/directory/page.htm

HBruijn
  • 72,524
  • 21
  • 127
  • 192