Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do you have access to the main Tomcat configuration? Tomcat can do virtual hosting, so you could set up a separate virtual host with a simple webapp to do the redirecting.</p> <p><strong>conf/server.xml</strong></p> <pre class="lang-xml prettyprint-override"><code>&lt;Engine name="Catalina" defaultHost="localhost"&gt; &lt;Host name="localhost" appBase="webapps" ...&gt; &lt;!-- current configuration, this Host will serve www.example.com --&gt; &lt;/Host&gt; &lt;Host name="example.com" appBase="nonwww-webapps" /&gt; &lt;/Engine&gt; </code></pre> <p><strong>nonwww-webapps/ROOT/WEB-INF/web.xml</strong></p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" ?&gt; &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt; &lt;servlet&gt; &lt;servlet-name&gt;redirectToWww&lt;/servlet-name&gt; &lt;jsp-file&gt;/WEB-INF/redirect.jsp&lt;/jsp-file&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;redirectToWww&lt;/servlet-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p><strong>nonwww-webapps/ROOT/WEB-INF/redirect.jsp</strong></p> <pre><code>&lt;% response.sendRedirect("http://www.example.com" + request.getRequestURI() + (request.getQueryString() == null ? "" : ("?" + request.getQueryString()) )); %&gt; </code></pre> <p>Or alternatively, if you want a 301 instead of 302 redirect</p> <pre><code>&lt;% response.setStatus(301); response.setHeader("Location", "http://www.example.com" + request.getRequestURI() + (request.getQueryString() == null ? "" : ("?" + request.getQueryString()) )); response.setHeader("Connection", "close"); %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload