-1

Expected behavior: Requests to example.com should redirect to example.com/.

Problem: Requests in a browser (Firefox) to example.com succeed. Requests in a browser to example.com/ redirect to example.com, which is backwards. With curl, neither request redirects and both serve the same content.

$ curl -D - example.com
HTTP/1.1 200 OK
Date: Sun, 23 Oct 2011 05:54:28 GMT
Content-Type: text/plain;charset=ISO-8859-1
Content-Length: 27
Connection: close

Servlet handling request: /index.html

$ curl -D - example.com/
HTTP/1.1 200 OK
Date: Sun, 23 Oct 2011 06:01:24 GMT
Content-Type: text/plain;charset=ISO-8859-1
Content-Length: 27
Connection: close

Servlet handling request: /index.html

Direct requests to Tomcat behave as expected.

$ curl -D - localhost:8080/myapp
HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Location: http://localhost:8080/myapp/
Transfer-Encoding: chunked
Date: Sun, 23 Oct 2011 05:50:20 GMT

<html><body><p>Redirecting to <a href="http://localhost:8080/myapp/">http://localhost:8080/myapp/</a></p></body></html>

I believe the problem is with my reverse proxy configuration. (I'm serving static content by Apache from the /a directory in the webapp.)

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /usr/share/tomcat7/webapps/myapp

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/a/
    RewriteRule (.*) ajp://localhost:8009/myapp$1 [P]

    <Directory /usr/share/tomcat7/webapps/myapp/a>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /usr/share/tomcat7/webapps/myapp>
        Order deny,allow
        Deny from all
    </Directory>
</VirtualHost>
1
  • I wish the person who voted my question down would explain why.
    – mqsoh
    Oct 23, 2011 at 7:02

1 Answer 1

1

http://example.com/ is absolutely same as http://example.com - both are requests to www.example.com path /. Path can't be empty: "If the abs_path is not present in the URL, it MUST be given as "/" when used as a Request-URI for a resource". So, there are no redirects for /, it's probably just a different behavior of different UI's.

But, it is different with /myapp: /myapp/ and /myapp is two different URL's and here you can do redirects, serve different pages and so on.

2
  • I actually can't do the redirect from /myapp to /myapp/ because the servlet is detecting the same request (see the first two output blocks in my question). Regardless of what's allowed by the protocol, I'd like the request through the reverse proxy to be handled the same as if my servlet were handling it directly.
    – mqsoh
    Oct 23, 2011 at 7:01
  • I meant than protocol allows you to do this. What tomcat can and what cannot only depends on tomcat. With apache httpd for example, you can easily make such redirect, but you can never make redirect from example.com to example.com/, regardless of software you are running. And I'm actually can't see any problem in your output.
    – rvs
    Oct 23, 2011 at 7:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .