Forum Moderators: phranque

Message Too Old, No Replies

Redirect not working using direct https address

Full scheme in ServerName breaks redirection

         

dmwaff

4:19 pm on Apr 21, 2011 (gmt 0)

10+ Year Member



Will someone please help me understand why when I specify the full scheme in the ServerName directive verses just the FQDN it breaks just this one request?

ServerName [example.com:443...]
-- verses --
ServerName example.com


Quote from ASF docs
"The ServerName directive sets the request scheme, hostname and port that the server uses to identify itself. This is used when creating redirection URLs....Sometimes, the server runs behind a device that processes SSL, such as a reverse proxy, load balancer or SSL offload appliance. When this is the case, specify the https:// scheme and the port number to which the clients connect in the ServerName directive to make sure that the server generates the correct self-referential URLs."


Problem Summary:
Request http://example.com/PAGE redirection and protocol switch to longer true full uri works.
Request [example.com...] returns a 404.



Here is my reduced configuration. I know it is duplication and the Redirect directive is a better choice. I'll deal with that in the June release. Also, I did testing with Redirect/RedirectMatch and same behaviors; however mod_rewrite gives me a look under-the-hood.

LOAD BALANCER
-------------
F5 Virtual Server (VIP:80) performing generic HTTP to Apache.
Member webserver1:8080
Member webserver2:8080

F5 Virtual Server (VIP:443) performing (SSL offloaded here) HTTPS to Apache.
Member webserver1:8443
Member webserver2:8443

HTTP Server
-----------
# HTTP container (works)
<VirtualHost IP:8080>
ServerName http://example.com:80
RewriteRule ^/PAGE [%{HTTP_HOST}...] [L]
<Location /full/uri/path/PAGE>
proxy junk
</Location>
</VirtualHost>

# HTTPS container (error 404)
<VirtualHost IP:8443>
ServerName [example.com:443...]
RewriteRule ^/PAGE [%{HTTP_HOST}...] [L]
<Location /full/uri/path/PAGE>
proxy junk
</Location>
</VirtualHost>

Solution:
# HTTPS container without the full scheme works, I don't understand why?
<VirtualHost IP:8443>
ServerName example.com
RewriteRule ^/PAGE [%{HTTP_HOST}...] [R=302,L]
<Location /full/uri/path/PAGE>
proxy junk
</Location>
</VirtualHost>




rewrite.log snippet
[example.com...] without full scheme
------------
init rewrite engine with requested uri /PAGE
applying pattern '^/PAGE' to uri '/PAGE'
rewrite '/PAGE' -> 'https://example.com/full_uri/path/PAGE?action=displaylogin'
split uri=https://example.com/full_uri/path/PAGE?action=displaylogin -> uri=https://example.com/full_uri/path/PAGE, args=action=displaylogin
implicitly forcing redirect (rc=302) with [example.com...]
escaping [example.com...] for redirect
redirect to [example.com...] [REDIRECT/302]


rewrite.log snippet
[example.com...] with full scheme
------------
init rewrite engine with requested uri /PAGE
applying pattern '^/PAGE' to uri '/PAGE'
rewrite '/PAGE' -> 'https://example.com/full_uri/path/PAGE?action=displaylogin'
split uri=https://example.com/full_uri/path/PAGE?action=displaylogin -> uri=https://example.com/full_uri/path/PAGE, args=action=displaylogin
reduce [example.com...] -> /full_uri/path/PAGE
local path result: /full_uri/path/PAGE
prefixed with document_root to /docroot/full_uri/path/PAGE
go-ahead with /docroot/full_uri/path/PAGE [OK]

error_log: ... File does not exist: /docroot/full_uri/path

Of course 404, /full_uri/path is namespace <Location> not physical <Directory>. I don't understand why it is apparently internalizing the explicit redirection target.

Thanks in advance, David

dmwaff

8:49 pm on Apr 22, 2011 (gmt 0)

10+ Year Member



implicitly forcing redirect (rc=302) with https://www.example.com/full_uri/path/PAGE

Typo in my cleanup... no www in that line

jdMorgan

5:52 pm on Apr 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about temporarily commenting-out the existing RewriteRule, and using one that will rewrite *any* SSL request to a static test page that exists?

Note that there is a discrepancy between the VirtualHost port and the ServerName port -- 8443 versus 443.

If you wish to use mod_rewrite for *anything* or if you wish to allow users to use it for any purpose, then do not use mod_alias Redirect or RedirectMatch directives in the server config. This can lead to problems if mod_alias executes after mod_rewrite.

For example, an internal rewrite implemented with mod_rewrite, plus an external redirect implemented in mod_alias (and executed later due to module-processing order) will 'expose' the internally-rewritten filepath as a URL to the client. This is very rarely desirable.

The solution is to use mod_rewrite exclusively if any internal URL-to-filepath rewriting is to be used for any purpose in any context on this server. The directives will then be processed in a predictable config-and-htaccess-code order.

So I would NOT recommend "cleaning this up later" by re-coding to use the Redirect directive...

Jim