You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by jieryn <ji...@gmail.com> on 2013/07/20 06:36:59 UTC

Apache Tomcat 7.x: Host+Alias and HTTP 301

Greetings,

I'm using Apache Tomcat 7.0.42, with IBM Java 1.7.0-SR2, on SuSE SLED
11 Linux. I have multiple host names which resolve to the same
application context, e.g. app.host1.com (host) and app.host2.com
(alias). I have implemented this within conf/server.xml via Host and
Alias definitions.

Moving forward, I would like Apache Tomcat to send a permanent
redirect, HTTP 301, for any incoming request on app.host2.com to
app.host1.com. How can I achieve this? I no longer want both
app.host1.com and app.host2.com to work "invisibly" to the user; I
want the user to see the host1.com address in his/her browser and to
teach the user, perhaps very subtly, to use that host1.com hostname.

I have tried Tuckey's URLRewrite filter, with a condition on
type="hostname", but I can not seem to get it right--lots of strange
infinite loop redirection for SSO. Regardless, this seems like
something that Apache Tomcat should be able to handle pretty easily..

Any help is appreciated, thanks,
-Jesse

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache Tomcat 7.x: Host+Alias and HTTP 301

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Jeff,

On 7/22/13 10:09 AM, Jeffrey Janner wrote:
> First, you want to set up app.host2.com as a separate host.  That 
> might be all you need to do to make Tuckey's filter easier to 
> configure.

+1

It will also improve the performance of the "primary" host, because
the Filter need not be enabled on the "primary" host, only the
"alternative" host.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJR7XY+AAoJEBzwKT+lPKRYOIMP/1EFwaEdfFSMZUJAcSlkUjam
SKIiAHONbFq81YI1gSdzejidhtY5anpSEhmyZhb0vAw32C8gDz/zkFWnOdG3rG/+
yEZKtlu3zhcNPQYWk1C9oFws0v67Sv4sDEC5o2NSV+nqpjpmrxfi5N8eJPvVcYdM
/yFBIwCqEnL0dUpb2cnSmrK5BjOIZnSLeoShx8G0mXo0oDxzAGbNXnpQW4r6/l4C
jmz6SVffoiZgKCQQQpf6OONWz+JgE2XFEdhdTqMv85/767FCwg1fNo3Fhz3iX/Sz
XPlgUKUadQmTTgj0N+W29aNCw8ZReZmiQL8TuadQlN2jAn63wZVuPpbgs77MByz+
q3Y9Clx1iIi30HZDRRBw0sHJSOcSa2P/ZMnfJ18w7O4cRwu15xp/3LDlP0s9dnCY
OYT7jbjZ9MDkiFipNmxk667rZT+PjyK3ySkNrKRzUuz9+Xe9fSBs1WmQyRdF/nQV
fioGC7+lPNwB76ZeyCc5wxD9baJbOU5flwTRNW2Q9Hert3kv6WPZxe5JsSnAHRl6
mTBoztXIUqPx+Yh3wzKiNcLqi9VApoY88/Ni+tkcqo70q20kKuV2gi0HH/tJ/e2Y
OoR4DASmJKt2SX6nJ0rrFA4NzgiXcWKItfMzLOKDBHS0unwN7hOli8o9Mu+SwUGG
AxKlT8SbBNs+ZahQ+8wG
=B/14
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Apache Tomcat 7.x: Host+Alias and HTTP 301

Posted by Jeffrey Janner <Je...@PolyDyne.com>.
> -----Original Message-----
> From: jieryn [mailto:jieryn@gmail.com]
> Sent: Friday, July 19, 2013 11:37 PM
> To: Tomcat Users List
> Subject: Apache Tomcat 7.x: Host+Alias and HTTP 301
> 
> Greetings,
> 
> I'm using Apache Tomcat 7.0.42, with IBM Java 1.7.0-SR2, on SuSE SLED
> 11 Linux. I have multiple host names which resolve to the same
> application context, e.g. app.host1.com (host) and app.host2.com
> (alias). I have implemented this within conf/server.xml via Host and
> Alias definitions.
> 
> Moving forward, I would like Apache Tomcat to send a permanent
> redirect, HTTP 301, for any incoming request on app.host2.com to
> app.host1.com. How can I achieve this? I no longer want both
> app.host1.com and app.host2.com to work "invisibly" to the user; I want
> the user to see the host1.com address in his/her browser and to teach
> the user, perhaps very subtly, to use that host1.com hostname.
> 
> I have tried Tuckey's URLRewrite filter, with a condition on
> type="hostname", but I can not seem to get it right--lots of strange
> infinite loop redirection for SSO. Regardless, this seems like
> something that Apache Tomcat should be able to handle pretty easily..
> 
> Any help is appreciated, thanks,
> -Jesse
> 

Jesse -
Sounds like something I do all the time.
First, you want to set up app.host2.com as a separate host.  That might be all you need to do to make Tuckey's filter easier to configure.
For this type of redirect though, I use HttpRedirectFilter from zlatkovic.com (http://www.zlatkovic.com/httpredirectfilter.en.html) as I found it much easier to configure than the Tuckey software. As long as you understand basic regular expressions, you should have no problems with it.
Jeff


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache Tomcat 7.x: Host+Alias and HTTP 301

Posted by jieryn <ji...@gmail.com>.
Greetings,

On Sat, Jul 20, 2013 at 12:36 AM, jieryn <ji...@gmail.com> wrote:
> I have multiple host names which resolve to the same
> application context, e.g. app.host1.com (host) and app.host2.com
> (alias). I have implemented this within conf/server.xml via Host and
> Alias definitions.

Just to close the loop here, I eventually did solve this with
URLRewrite filter. The documentation I was looking at was inaccurate
or maybe just mismatched against the version of the library being
used.. Alas, here is the working URLRewrite rule:

  <rule>
    <note>Domain name change from $OLDHOST1, with $OLDHOST2 Alias, to
$NEWHOST.</note>
    <condition type="server-name" operator="equal"
next="or">$OLDHOST1</condition>
    <condition type="server-name" operator="equal">$OLDHOST2</condition>
    <from>^(.*)$</from>
    <to last="true" type="permanent-redirect">http://$NEWHOST/$1</to>
  </rule>

Thanks!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org