I cannot redirect my non www domain version to www with MovedContextHandler
, it does not have host to redirect to.
Both www.example.com
and example.com
point to my web server IP. When someone tries to open example.com
he is still able to access my site that way. I want for his browser to receive HTTP 301 redirection to www.example.com
instead. It is important for search rankings, as search engines must know example.com
and www.example.com
are one and the same.
As a bonus, when someone tries to access example.com/somepath/somepage.html
I want a HTTP 301 redirection to www.example.com/somepath/somepage.html
How do I proceed with that? Do I need to write my own handler or is there an easier way?
To avoid a cycle of redirections you have to define on what virtualhost this rule works.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.server.handler.MovedContextHandler">
<Set name="contextPath">/</Set>
<Set name="newContextURL">http://www.example.com</Set>
<Set name="permanent">true</Set>
<Set name="discardPathInfo">false</Set>
<Set name="discardQuery">false</Set>
<Set name="virtualHosts">
<Array type="String">
<Item>example.com</Item>
</Array>
</Set>
</Configure>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With