help from rewrite expert with a simple problem related to Java webapp context roots?
am 06.06.2007 12:46:59 von mjcconsultingI have a rather simple problem, but no time at the moment to figure
this out on my own. A Google search didn't turn any thing up, and I
didn't want to dig into mod_rewrite... thought some experts here might
know how to do what I'm trying to do:
What's the best way to do 3 simple things:
1. if user enters: http://context.company.com/*, REDIRECT them to
https://context.company.com/*
2. if user enters: /* (path not starting with /context), REDIRECT them
to /context/*
Now here's the tricky part
3. AFTER the user has been redirected to prepend "/context" if it is
missing, I need to strip this off to actually serve the page. For
example:
ServerName context.company.com
DocumentRoot /opt/company/webapps/company-context
- Assume /opt/company/webapps/company-context/page1.html exists
- If user requests http://context.company.com/, redirect to
https://context.company.com/
- If user requests https://context.company.com/page1.html, redirect to
https://context.company.com/context/page1.html, so this appears in
the browser address bar
- However user gets to https://context.company.com/context/page1.html,
it should get that page from
/opt/company/webapps/company-context/page1.html
(... NOT from /opt/company/webapps/company-context/context/
page1.html)
Thanks in advance,
Mike
P.S. Why am I trying to do this?
Normally, java webapp is run as a context within ROOT webapp, so user
will enter:
http://www.company.com/context/page1.html
with
ServerName www.company.com
DocumentRoot /opt/company/webapps/company-www
Alias /context /opt/company/webapps/company-context
to see page /opt/company/webapps/company-context/page1.html
But occasionally, we will need to serve company-context webapp on a
separate site - still as a context, but with a dummy ROOT application
from Apache's perspective. I want the path to the page to be the same,
with only the FQDN different, so user will enter:
http://context.company.com/context/page1.html
with
ServerName context.company.com
DocumentRoot /opt/company/webapps/company-context
# note no context alias here, just rewrite rules to fix up the url
to see page /opt/company/webapps/company-context/page1.html
To do this, it seems I will need to redirect the user to include the
context if not specified, but then exclude the context to display the
page in the right spot when running standalone, since the context is
only added by the alias when this webapp runs as a context on top of
the ROOT application.
Hope my description is clear. Thanks in advance if anyone can save me
a few hours of trial and error to get this working. Thought it was a
common problem?